Question

I am working in a JTabbedPane inside of a JFrame. I have a jRadioButton that I need when selected to activate/enable two jSpinner controls that select date & time. I cannot find a reference for how this should be completed and this is not a school project.

I need the jSpinner to be disabled while jRadioButton is clear and enabled while selected. The jRadioButton is part of a ButtonGroup of two buttons. The other jRadioButton when enabled will open a jTextField to enter data.

Any help or links to documentation will be helpful. Everything I have found so far doesn't describe how to link these two.

Thanks

Was it helpful?

Solution

Try a Listener on your radio buttons. Here is a simple example for the JRadioButton controlling the JSpinner. Of course you'd want to add some logic/another listener to handle your other components as well, (the JTextField etc).

Hope this helps!

    final JRadioButton spinnerButton = new JRadioButton("Spinner Enabled");
    spinnerButton.addItemListener(new ItemListener(){
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (spinnerButton.isSelected()){
                spinner.setEnabled(true);
            } else {
                spinner.setEnabled(false);
            }
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top