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
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
[Originally posted by bparanj]

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

mItem = new JMenuItem("Exit");
lst = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(
"Do you want to quit this application ?",
== JOptionPane.YES_OPTION)
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