0

I have been created a delete button which delete some text from text field. But when I click this button and delete the text the button still selected. I want to deselect this button after clicking it.

I tried this code but it doesn't work

 private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    jTextField2.setText("");
    jCheckBox1.setSelected(false);
    jTextField4.setText("");
    jTextField5.setText("");
    jTextField6.setText("");
    jButton1.setSelected(false);
}

How to make a JButton not selected after clicking it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Basma Ali
  • 45
  • 7

3 Answers3

1

So, based on jToggleButton1ActionPerformed, I suspect you are using a JToggleButton, which has two states, selected and unselected, which probably isn't what you want.

Instead, just use a JButton

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1
jTextFieldN.requestFocusInWindow();

Be sure to read the Java Docs for the method..


Also, as mentioned elsewhere you'll need a JButton rather than JToggleButton for this.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

use a JButton and in the buttonClick event,

JButton.setEnabled(false);
Chatz
  • 338
  • 2
  • 10