The moose likes Swing / AWT / SWT / JFace and the fly likes confirm dialog not Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "confirm dialog not " Watch "confirm dialog not " New topic
Author

confirm dialog not

Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 57

Hello Experts !

I have this piece of code down below. What I am confused about is why, when the confirmation dialog box appears and I click on the No button, the JVM exits the loop and displays the sum of numbers, but when I select this button using the tab key, the JVM considers this input as YES_OPTION, and the code reacts to this option accordingly.

Thank you so so much !

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 26720
I tried some similar code and couldn’t reproduce your error. Now, yes = 0, no = 1 and cancel = 2, which is exactly what I got by running this little program:I suggest you put some debugging print statements into that method, and see what you get.
Michael Dunn
Rancher

Joined: Jun 09, 2003
Posts: 4041
the optionPanes have a default button (react to enter key), generally yes/ok/whatever
so even though you've tabbed to 'no' and that button has focus (the dotted square around the text),
hitting enter will fire the default button = ok/yes/whatever.

to fix, add this line as the first line of the program
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 57

Thank you very much Ritchie Michael for your detailed answers, it helps a lot a greenhorn. we are luck to have you !

I have tried putting this piece of code on first line of the program as instructed, but it gives me this error :

[error message]

error: ';' expected
import javax.swing.UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);

[/error message]

in this message the ^ sign points out to the bracket (

this is my version of Java

java version "1.7.0"
Java(TM) SE Runtime Environment (build pwi3270-20110906_01)
IBM J9 VM (build 2.6, JRE 1.7.0 Windows Server 2003 x86-32 20110810_88604 (JIT enabled, AOT enabled)
J9VM - R26_Java726_GA_20110810_1208_B88592
JIT - r11_20110810_20466
GC - R26_Java726_GA_20110810_1208_B88592
J9CL - 20110810_88604)
JCL - 20110809_01 based on Oracle 7b147

and here is the code again, maybe I did something wrong.

Please advice,
marius

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

You should use what Michael said you should use. And realizing that it's executable code, you would naturally put it as the first executable statement.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 3905
import javax.swing.UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);


you need to break that up. the compiler is trying to tell you an import statement is just that.

import javax.swing.UIManager;

then inside your main()

UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);

I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
 
jQuery in Action, 2nd edition
 
subject: confirm dialog not
 
Threads others viewed
JFrame window closing
window closing
Input continuously collecting
OptionDialog Problem
JOptionPane confirmation dialog box functionality issue
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture