[英]Calling actionlistener of a disabled JButton
我正在做一些需要從另一個函數調用禁用的jbutton
的actionlistner
的事情。 怎么做?
制作一個新的方法,該方法將由禁用的jbutton調用,並在其中單擊該按鈕時將執行的所有代碼都寫入其中。 您不能以其他方式調用actionlistiner
。
...
JButton disButton = new JButton("Disabled");
disButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
//do not write any statement here
doSomething();
}
});
...
private void doSomething() {
//all action event execution code here
System.out.println("I am in the action listener");
}
....
//in the other method or another button click event call doSomething()
//even button is disables like
JButton Button = new JButton("Submit");
Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
doSomething();
}
});
//or from another method
public void method() {
doSomething();
}
您不能在disabled
GUI控件上調用/執行actions
,這實際上是disable
意思
您可以做的是創建一個單獨的通用方法,如doClick()
並在需要的地方調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.