user3143553
user3143553

Reputation:

how giving the user error messages?

I wrote a little java tool with a GUI, that needs a source path (e.g. Music folder) and a destination path (e.g. USB device) entered by the user.

If the user selects a drive that is not available (e.g. select USB device and unplug it afterwards from the PC) I need to output a error message, like "device E:\ not available".

I would like to know, what is a good or professional way to create and show messages in a JFrame GUI? Show messages in a jTextArea? Via Popup?

Right now, I use this solution from Joffrey, but it show the whole error output from the console - what a usual user not understands. How to set output stream to TextArea

Upvotes: 1

Views: 114

Answers (3)

Yannick De Turck
Yannick De Turck

Reputation: 412

JOptionPane.showMessageDialog(myPanel,
                "Something went wrong",
                "Error!",
                JOptionPane.ERROR_MESSAGE);

Upvotes: 1

jzd
jzd

Reputation: 23629

As nachokk recommended for display the JXErrorPane is very useful to be able to show a human readable message to a user and still have the stack trace accessible.

The other side will be translation of an exception into a message that a user understands. You will need to possibly add additional catch statements that handle each Exception that should generate a different message to the user.

The message text from some exceptions is normally not clear enough on its own. In your app a "File Not Found" message would need to explain to the user if it is the destination or source path.

Upvotes: 1

nachokk
nachokk

Reputation: 14413

If you don't mind to use 3rd party libraries, i recommend to use JXErrorPane by swingX otherwise you can use a simple JOptionPane that is very powerful and customizable.

Upvotes: 3

Related Questions