Reputation: 359
I want to ask if there is a way to make the text field active and inactive according to the radio button.
For example, the textfield will be inactive and when the user click on the radio button, the textfield will be active.
I am using Java language and NetBeans program
Upvotes: 1
Views: 24656
Reputation: 44073
You could have two radio buttons for representing the active/inactive state. Add an action listener to each and when the 'active' one is pressed you call setEditable(true) on the JTextField and when the 'inactive' JRadioButton is called you call setEditable(false).
JTextField textField = new JTextField();
JRadioButton activeButton = new JRadioButton("Active");
JRadioButton inactiveButton = new JRadioButton("Inactive");
activeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
textField.setEditable(true);
}
});
inactiveButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
textField.setEditable(false);
}
});
Upvotes: 3