Java Forum / GUI / September 2005
How to layout OK and Cancel buttons
Nomak - 08 Sep 2005 11:00 GMT Hello,
is there a satndard way to layout the buttons "OK" and "Cancel" for java programs? I'm asking because java already ask to use some defined icons if possible.
I generally put "OK" to the left and "Cancel" to the right. Is this "the" way?
TIA
Sameer - 08 Sep 2005 11:38 GMT Try experimenting with JOptionPane-
Show an error dialog that displays the message, 'alert': JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
Show an internal information dialog with the message, 'information': JOptionPane.showInternalMessageDialog(frame, "information",
"information", JOptionPane.INFORMATION_MESSAGE);
Show an information panel with the options yes/no and message 'choose one': JOptionPane.showConfirmDialog(null, "choose one", "choose one", JOptionPane.YES_NO_OPTION);
Show an internal information dialog with the options yes/no/cancel and message 'please choose one' and title information: JOptionPane.showInternalConfirmDialog(frame, "please choose one", "information", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
Show a warning dialog with the options OK, CANCEL, title 'Warning', and message 'Click OK to continue': Object[] options = { "OK", "CANCEL" }; JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
Show a dialog asking the user to type in a String: String inputValue = JOptionPane.showInputDialog("Please input a value");
Show a dialog asking the user to select a String: Object[] possibleValues = { "First", "Second", "Third" }; Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
Hope this will help you.
Nomak - 08 Sep 2005 12:20 GMT The internal messages didn't work. The others were OK:
/* * Show an error dialog that displays the message, 'alert' */ JOptionPane.showMessageDialog(parent, "alert", "alert", JOptionPane.ERROR_MESSAGE); /* * Show an information panel with the options yes/no and * message 'choose one': */ JOptionPane.showConfirmDialog(parent, "choose one", "choose one", JOptionPane.YES_NO_OPTION); /* * Show a warning dialog with the options OK, CANCEL, title * 'Warning', and message 'Click OK to continue': */ Object[] options = { "OK", "CANCEL" }; JOptionPane.showOptionDialog(parent, "Click OK to continue", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); /* Show a dialog asking the user to type in a String: */ String inputValue = JOptionPane.showInputDialog(parent, "Please input a value"); /* Show a dialog asking the user to select a String: */ Object[] possibleValues = { "First", "Second", "Third" }; Object selectedValue = JOptionPane.showInputDialog(parent, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
the yes/ok is always on the left.
I wont dig into locale specific orientation for now. Thx for your help.
Thomas A. Russ - 08 Sep 2005 21:46 GMT > is there a satndard way to layout the buttons "OK" and > "Cancel" for java programs? I'm asking because java already ask to use > some defined icons if possible.
> I generally put "OK" to the left and > "Cancel" to the right. Is this "the" way? TIA Well, this is a bit tricky, because the general convention about where to put those buttons is platform-dependent. In particular, Windows and the MacOS have different placements. Fortunately, the JOptionPane classes do this in a platform appropriate manner.
I don't know if there is some information in the LookAndFeel that allows you to figure this out on your own. Any help?
 Signature Thomas A. Russ, USC/Information Sciences Institute
Graham Perks - 09 Sep 2005 02:36 GMT > I don't know if there is some information in the LookAndFeel that allows > you to figure this out on your own. Any help? Foam's layout manager handles the location of OK, Cancel, and Help buttons correctly depending on the current platform.
Foam is at http://www.computersinmotion.com
Cheers, Graham Perks.
Karsten Lentzsch - 09 Sep 2005 18:50 GMT > is there a satndard way to layout the buttons "OK" and "Cancel" > for java programs? I'm asking because java already ask to use > some defined icons if possible. If you layout OK, Cancel, Apply, Help, etc. in a custom Swing panel or dialog, there's no standard way. However, there are good ways to do so.
I provide a free layout system that assist you in getting good design quickly. The layout of button bars and stacks is addressed in three levels:
1) the layout manager is technically able to layout button bars for all platforms I'm aware of. This is in detail more complicated than you may know. For example, on Windows an OK command button has a minimum width of 50 dialog units (dlu). And many layout managers don't handle dlus. 2) the layout system comes with a ButtonBarBuilder that assists you in building button bars that comply with the platform's style. It uses the correct size unit (dlu vs. pixel), the correct logical gaps, and the default button order (OK Cancel vs. Cancel OK). 3) the layout system comes with a ButtonBarFactory that vends prepared button bars for frequently used bars.
See the JGoodies Forms Demo for a quick introduction: http://www.jgoodies.com/freeware/formsdemo/index.html
Find more information about the open source JGoodies Forms: http://www.jgoodies.com/freeware/forms/index.html
> I generally put "OK" to the left and "Cancel" to the right. > Is this "the" way? It depends. If you use the correct size, the correct gaps, the correct margins, then it is the way for Windows apps. On the Mac you'd layout Cancel, OK.
Hope this helps. Kind regards, Karsten Lentzsch
Roedy Green - 10 Sep 2005 17:47 GMT >is there a satndard way to layout the buttons "OK" and "Cancel" for java programs? I'm asking because java already ask to use some defined icons if possible. > >I generally put "OK" to the left and "Cancel" to the right. Is this "the" way? Follow JOptionPane's lead.
OK on left, Cancel on right.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|