Samooramad
asked on
option pane questions
hi experts
I have two questions:
can you get an option pane with a check box in it that will affect the outcome? for example if it is checked then you save a certain part of the program and if not it saves the default..whatever..
second I need an example of an option pane that would have three buttons. yes, no, and cancel and how to know know which button was pressed and accordingly take action
thanks
I have two questions:
can you get an option pane with a check box in it that will affect the outcome? for example if it is checked then you save a certain part of the program and if not it saves the default..whatever..
second I need an example of an option pane that would have three buttons. yes, no, and cancel and how to know know which button was pressed and accordingly take action
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Next time you better ask one question per ... errrh question ;°)
ASKER
yeah I should I guess :)
thanks for the help
thanks for the help
Thanks
import javax.swing.*;
import java.awt.*;
public class DialogBox
{
public static void main(String[] args)
{
JPanel fields = new JPanel();
JLabel label = new JLabel("Some text:");
JCheckBox cb = new JCheckBox();
fields.add(label);
fields.add(cb);
String[] options = {"Yes", "No", "My Cancel"};
int input = JOptionPane.showOptionDial
null, // parentComponent
fields, // message
"Enter your input", // title
JOptionPane.YES_NO_CANCEL_
JOptionPane.QUESTION_MESSA
null, // icon
options, // options
options[0] // initialValue
);
if (input == 0) {
System.out.println("Yes pressed. CheckBox selected = " + cb.isSelected());
}
else if (input == 1) {
System.out.println("No pressed. CheckBox selected = " + cb.isSelected());
}
else if (input == 2) {
System.out.println("Cancel
}
System.exit(0);
}
}