简体   繁体   English

让JButton手动保持沮丧

[英]Making a JButton stay depressed manually

我想让JButton保持按下状态,并且在某些事件发生之前无法再次按下是否有一种简单的方法可以做到这一点?

You should probably look at the JToggleButton class. 您应该查看JToggleButton类。 Associate it with an Action which calls setEnabled(false) to disable interaction. 将其与调用setEnabled(false)以禁用交互的Action相关联。

Once your event happens you call setEnabled(true) and setSelected(false) to restore the original state of the button. 一旦您的事件发生,您调用setEnabled(true)和setSelected(false)来恢复按钮的原始状态。

Perhaps you just want to disable the button? 也许你只想禁用按钮? Try setEnabled(false) in your callback for the button. 在回调按钮中尝试setEnabled(false)

I think you should have a look at the JButton Swing class Here . 我想你应该看看将JButton Swing类在这里 It allows you to have a 2 state button, and so for what you need, you may just need to attach your button to some boolean, allowing it to be selected or not. 它允许你有一个2状态按钮,所以对于你需要的,你可能只需要将你的按钮附加到某个布尔值,允许它被选中或不被选中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM