Search code examples
javaswingjpaneljbuttonjoptionpane

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


We have a Swing application with a lot of input dialogs featuring okay and cancel buttons.

I've noticed that in JOptionPane the order of the okay and cancel buttons changes depending on platform. On Windows it's okay/cancel and on Unix it's cancel/okay.

Where we've added our own okay and cancel buttons I'd like the order of them to match the order they show in JOptionPane for consistency.

I was wondering if there's a way to interrogate the UIManager to find out what the correct order should be for the current look and feel or platform.

Thanks in advance. Matt


Solution

  • The order of the buttons in a JOptionPane is controlled by

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

    If isYesLast is true then the button order is reversed (e.g. yes/no/cancel -> cancel/no/yes)