如何实现三态切换按钮?我正在使用 eclipse 和 windowBuilder 并且我正在编写一个必须具有三态按钮的程序。我使用了 JToggleButtons 和它们的两个状态,因为两个 bu 无法实现第三个状态。我能做些什么?
PS我想要三个图标状态。
如何实现三态切换按钮?我正在使用 eclipse 和 windowBuilder 并且我正在编写一个必须具有三态按钮的程序。我使用了 JToggleButtons 和它们的两个状态,因为两个 bu 无法实现第三个状态。我能做些什么?
PS我想要三个图标状态。
也许你可以看看使用的代码com.jidesoft.swing.TristateCheckBox
:
见TristateCheckBox.java
。
它确实继承自JToggleButton
并具有三种不同的图标状态。
/**
* Maintenance tip - There were some tricks to getting this code
* working:
* <p/>
* 1. You have to overwite addMouseListener() to do nothing
* 2. You have to add a mouse event on mousePressed by calling
* super.addMouseListener()
* 3. You have to replace the UIActionMap for the keyboard event
* "pressed" with your own one.
* 4. You have to remove the UIActionMap for the keyboard event
* "released".
* 5. You have to grab focus when the next state is entered,
* otherwise clicking on the component won't get the focus.
* 6. You have to make a TristateDecorator as a button model that
* wraps the original button model and does state management.
*
* @author Dr. Heinz M. Kabutz
*/
public class TristateCheckBox extends JCheckBox {