在 Java 中禁用启用 JButton

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9682046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:06:16  来源:igfitidea点击:

Disable enable JButton in Java

javaswing

提问by 3D-kreativ

I have a problem I'm trying to disable JButton with setEnabled(false) like this:

我有一个问题,我正在尝试使用 setEnabled(false) 禁用 JButton,如下所示:

ButtonNewCustomer.setEnabled(false);

But this didn't work so then I imported the Applet packages, but still not working, then I discovered that I also needed to use extends Applet in the class, but the problem is that I'm already using extends for other things like this:

但这不起作用,所以我导入了 Applet 包,但仍然无法正常工作,然后我发现我还需要在类中使用 extends Applet,但问题是我已经将扩展用于其他类似的东西:

public class GUI4EX extends JFrame implements ActionListener {
...
}

I have tried to add Applet, but this dont't work! Is there a way to solve this? Thanks!

我曾尝试添加 Applet,但这不起作用!有没有办法解决这个问题?谢谢!

EDIT: It's working know! The problem was a misspelling of the buttonNewCustomer. The first letter 'b' was 'B'. Sorry! And thanks for the help!

编辑:它的工作知道!问题是 buttonNewCustomer 的拼写错误。第一个字母“b”是“B”。对不起!并感谢您的帮助!

回答by 3D-kreativ

use setEnabled(true)to enable button...

用于setEnabled(true)启用按钮...

回答by Jatin

Make sure that you are disabling/enabling your button before setting the frame's visibility.

确保在设置框架的可见性之前禁用/启用按钮。