java - 使用 JToggleButton 在三种状态之间切换

标签 java eclipse togglebutton windowbuilder

如何实现三态切换按钮?我正在使用 eclipse 和 windowBuilder,并且正在编写一个必须具有 3 态按钮的程序。我使用了 JToggleButtons 和它们的两个状态,但不能实现第三个状态。我能做什么?

附言我想要三个图标状态。

最佳答案

也许你可以看看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 {

关于java - 使用 JToggleButton 在三种状态之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8115601/

相关文章:

android - 如何永久禁用切换按钮?

java - Java中的对象大小

具有恒定堆大小的 Java 进程在操作系统中分配越来越多的内存

javascript - Eclipse Javascript——如何订购多个文件?

Java:Thread.currentThread().sleep(x) 与 Thread.sleep(x)

iphone - 按下时切换 UIButton 状态,就像一个开关

java - 不可能(?): NullPointerException on ConcurrentLinkedQueue. 大小()

java - 如何将值发送到 postgres 函数?

java - 调用特定方法时创建断点

android - 如何在 Android 中以编程方式打开和关闭切换按钮?