Is there a way to determine the correct order of the Okay / Cancel buttons?

We have a Swing application with a lot of input dialogs showing ok and cancel buttons.

I noticed that in JOptionPane, the order of the ok and cancel buttons changes depending on the platform. On Windows this is normal / undo, while on Unix it is undo / normal.

If we added our own ok and cancel buttons, I would like their order to match the order they show in JOptionPane to ensure consistency.

I was wondering if there is a way to poll UIManager to find out what the correct order should be for the current look and platform.

Thanks in advance. Matt

+4
source share
3 answers

The order of buttons in JOptionPane is controlled

boolean isYesLast = UIManager.getDefaults().getBoolean("OptionPane.isYesLast");

If isYesLasttrue, then the order of the buttons is canceled (for example, yes / no / cancel → cancel / no / yes)

+5
source

You can use this:

Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
0
source

Yes, there is, but not in the way you expected. You must create your own OptionPane class. And you have to stretch from JOptionPane. This way you can design where your buttons will be placed. I personally would recommend finding another solution.

0
source

Source: https://habr.com/ru/post/1607801/


All Articles