如何在 Java 中使 JButton 变灰

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13183920/
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-10-31 11:48:12  来源:igfitidea点击:

How to grey out JButton in Java

javaswingnetbeansjbutton

提问by Chin

How can I grey in/out a Swing Jbutton? What method can I use? Also, how can I make it greyed out by default in Netbeans?

如何使 Swing Jbutton 变灰/变灰?我可以使用什么方法?另外,我怎样才能让它在 Netbeans 中默认变灰?

回答by WilliamShatner

button.setEnabled(false); 

The above should grey out a button just fine. I would make sure you have the documentation bookmarked or downloaded and read up on it a bit

上面的按钮应该变灰就好了。我会确保您将文档添加为书签或下载并仔细阅读

Edit

编辑

My assumption is that you are using the GUI creator in Netbeans. I would highly advise reading up on swing and learning the language rather than the IDE (there could be times when you have to use a different IDE than Netbeans and wouldn't have a clue how to do GUIs)

我的假设是您正在使用 Netbeans 中的 GUI 创建者。我强烈建议阅读 Swing 并学习语言而不是 IDE(有时您必须使用与 Netbeans 不同的 IDE,并且不知道如何制作 GUI)