Radio buttons in netbeans (probably simple solution for exp users)

Soldato
Joined
26 Nov 2005
Posts
3,839
Location
Doon the Bay (Newcastle)
Hi.

Finally had time to explore Netbeans a bit and its helped a lot in designing a GUI, but now i'm going off the basic set-up to asking a bit more of it.

What i want is when i selected a certain radio button, other radio buttons appear, and when its deselected for them to hide again.

How do i do that?

Thanks. :D
 
Call setVisible(false); the radio buttons you want to hide from within the action listeners for the clicked ones.
 
This is one way of doing it, I have done this in the past when working with a GUI built by netbeans. When building the GUI I always change the variable names of the components, it makes it easier to refer to them in any code you write.

Code:
// Define this at the top of the GUI class
private JRadioButton[] rads;

// Define this in the constructor AFTER initComponents()
// radio1, radio2 etc. are the variable names of the butttons you want to show/hide
rads = new JRadioButton[] {radio1, radio2, radio3};

// Define this method somewhere in the class
private void showRads(boolean state) {
	for (JRadioButton j : rads)
	{
		j.setVisible(state);
	}
}

//Make a call to the showRads() method from the action listener
showRads(true);
 
Back
Top Bottom