JOptionPane update to change component state

there is a method in my GUI project for displaying a JOptionPane with several components on it, 2 of these ButtonGroups components with 2 JRadioButtons in each, the first button is selected by default in the first group, the second button is selected by default in the second group, in the second group I want so that the first button is disabled until the second button in the first group is selected, i.e. if the user is satisfied with the default choice in BG1, then they can 'make a choice in BG2 only if they make a second choice in BG1, they can have another option in BG2.

Is this possible when using JOptionPane ?

We studied the manuals for JDialog , JOptionPane and other studies, but none of them turned out to be useful in this case. if someone could give me a little indication of a possible solution that would be fantastic ...

+7
source share
3 answers

I do not think this is possible with JOption. but I think this is possible with JDialog.

examble:

when you open the dialog, you can use the JFrame command (here you must write your window name) .enable (false)

you could get it to close the button in the aisle you might have a checkbox when the checkbox is checked it will show a button, and when you click, it can make an invisble button

0
source

The best thing for JDialog

Since JOptionPane does not support this part of the components.

0
source

In the elective.addActionListener I named the wrong variable, had cp12 instead of cp6 , placed my short code below, everything is fine, thanks

  public void displayAddSomething(ArrayList<String> items) { // cut down version only showing the button panels // initialising the variables JPanel buttPanel = new JPanel(new GridLayout(0, 1)); JPanel pointPanel = new JPanel(new GridLayout(0, 1)); JRadioButton core = new JRadioButton("Core Item: ", true); final JRadioButton elective = new JRadioButton("Elective Item: "); final JRadioButton cp6 = new JRadioButton("6 Points: "); JRadioButton cp12 = new JRadioButton("12 Points: ", true); ButtonGroup bg1 = new ButtonGroup(); ButtonGroup bg2 = new ButtonGroup(); // adding the buttons to buttPanel and the button group 1 buttPanel.add(new JLabel("Select Course Type")); buttPanel.add(core); buttPanel.add(elective); buttPanel.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2)); bg1.add(core); bg1.add(elective); // add buttons pointPanel and bg2 pointPanel.add(new JLabel("Select Credit Points")); pointPanel.add(cp6); pointPanel.add(cp12); pointPanel.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2)); bg2.add(cp6); bg2.add(cp12); cp6.setEnabled(false); // add action listener for each of bg1 buttons so if event // occurs the cp6 button will toggle between enabled and disabled. elective.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cp6.setEnabled(true); }}); core.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cp6.setEnabled(false); }}); Object[] message = {buttPanel,pointPanel}; int result = JOptionPane .showOptionDialog( this, message, "...some text...", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "Submit", "Cancel" }, "Default"); if (result == JOptionPane.OK_OPTION) { // collecting all the input values in a string array to pass to // another class for processing by the model... } else if (result == JOptionPane.NO_OPTION) { JOptionPane.showMessageDialog(this, "You Have Elected Not to do anything At This Time", "YOU HAVE COME THIS FAR AND YOU QUIT NOW....", JOptionPane.QUESTION_MESSAGE); } } 
0
source

All Articles