The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
import-bot (20211) [Avatar] Offline
#1
Re: confirm dialog problem
[Originally posted by matt]

There is no problem with this code.
The problem is with JOptionPane itself.
For some reason the Swing team decided that
the default behavior should be that if you
press ENTER, no matter what has the focus,
the default button (in this case the OK
button) should be invoked.
In my opinion this is seriously wrong.

The best way to work around the problem is
to build your own modal dialog.

Also note another problem: all JOptionPane
dialogs are resizable. I am against this
decision as well.

In general, I am not a fan of JOptionPane
at all. It has too many major design flaws.
I recommend building your own dialogs instead
of using this class.
import-bot (20211) [Avatar] Offline
#2
[Originally posted by bparanj]

In chapter 14, DialogBoxes.java the following piece of code has a problem.

mItem = new JMenuItem("Exit");
mItem.setMnemonic('x');
lst = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(
DialogBoxes.this,
"Do you want to quit this application ?",
BOX_TITLE, JOptionPane.YES_NO_OPTION)
== JOptionPane.YES_OPTION)
System.exit(0);
}
};
mItem.addActionListener(lst);
mFile.add(mItem);
menuBar.add(mFile);
The problem is when I tab to the NO and hit enter, the application closes.
When I tab to the NO and hit space, the application does not close. Can you
please tell me how to fix the problem ?
Thank you for your time.
Bala Paranj