Making a JButton stay depressed manually

淺唱寂寞╮ 提交于 2020-01-15 04:56:06

问题


I would like to make a JButton stay pressed down and not be able to be pressed again until some event occurs is there an easy way to do this?


回答1:


Perhaps you just want to disable the button? Try setEnabled(false) in your callback for the button.




回答2:


You should probably look at the JToggleButton class. Associate it with an Action which calls setEnabled(false) to disable interaction.

Once your event happens you call setEnabled(true) and setSelected(false) to restore the original state of the button.




回答3:


I think you should have a look at the JButton Swing class Here. 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.



来源:https://stackoverflow.com/questions/1719166/making-a-jbutton-stay-depressed-manually

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!