Thursday, May 5, 2011

Text Field disabling in NetBeans

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

From stackoverflow
  • 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);
        }
    });
    
    3yoon af : It is work .. Thank you for help ..
    willcodejavaforfood : No problems mate :)
  • neceito que cuando le oprima al boton....toda la informacion digitada en unos text.... sea cojida para hacer unas operaciones..podria ayudarme?

0 comments:

Post a Comment