Disable JButton

when I disable the JButton, but why i can click it and perform a MouseClicked()?

how can i disable the button and it don't perform anything?

thank you

publicclass TestButtonextends javax.swing.JFrame{

/** Creates new form TestButton */

public TestButton(){

initComponents();

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

privatevoid initComponents(){

jButton1 =new javax.swing.JButton();

getContentPane().setLayout(null);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("jButton1");

jButton1.setEnabled(false);

jButton1.addMouseListener(new java.awt.event.MouseAdapter(){

publicvoid mouseClicked(java.awt.event.MouseEvent evt){

jButton1MouseClicked(evt);

}

});

getContentPane().add(jButton1);

jButton1.setBounds(0, 0, 73, 23);

pack();

}// </editor-fold>

privatevoid jButton1MouseClicked(java.awt.event.MouseEvent evt){

System.out.println("Muse Click");

}

/**

* @param args the command line arguments

*/

publicstaticvoid main(String args[]){

java.awt.EventQueue.invokeLater(new Runnable(){

publicvoid run(){

new TestButton().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

// End of variables declaration

}

[3218 byte] By [oliverwga] at [2007-11-27 8:30:08]
# 1
use an actionListener instead
Michael_Dunna at 2007-7-12 20:20:39 > top of Java-index,Desktop,Core GUI APIs...
# 2

Well I would say it is cause you added a mouse listener, so would respond whenever a mouse action is done.

Try using an ActionListener instead.

However, if you need to use the MouseListener, then you'll to need to check if the button is enabled or disabled before carrying out the action

ICE

icewalker2ga at 2007-7-12 20:20:39 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thank you!
oliverwga at 2007-7-12 20:20:39 > top of Java-index,Desktop,Core GUI APIs...