When I press JLabel
, I get a mousePressed
event call in which I want开发者_运维技巧 to disable a JButton
. However, nothing happens. Why is this?
Here is the JLabel
mousePress
event handler:
public void mousePressed(MouseEvent e) {
get_clickevent(false)
}
Here is the function that get call on mousePressed
:
public void get_clckevent(final boolean value){
java.awt.EventQueue.invokeLater(new Runnable() {
boolean valu = value;
public void run() {
if (valu == false) {
btnSave.setEnabled(false); //here is button that does not disable.
}
}
});
The code you have looks free of problems. Make sure btnSave is actually pointing to the button you think it is. Also make sure your mouse event is actually happening. (Add a println somewhere to make sure your button is truly set to disabled).
Also instead of:
if (valu == false) {
Just do:
if (!valu) {
And what is the point of this line:
boolean valu = value;
Just use value instead of valu in your if statement.
精彩评论