Disabling a textbox in NetBeans

I want to ask if there is a way to make the textbox active and inactive according to the radio button.

For example, the text box will be inactive, and when the user clicks on the radio button, the text box will be active.

I am using Java language and NetBeans program

+1


a source to share


1 answer


You can have two toggles to show active / inactive state. Add an action listener to each, and when "active" is clicked, 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);
    }
});

      

+3


a source







All Articles