views:

508

answers:

2

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

+1  A: 

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);
    }
});
willcodejavaforfood
It is work ..Thank you for help ..
3yoon af
No problems mate :)
willcodejavaforfood
A: 

neceito que cuando le oprima al boton....toda la informacion digitada en unos text.... sea cojida para hacer unas operaciones..podria ayudarme?