2

3 状態のトグル ボタンを実装するにはどうすればよいですか? 私は eclipse と windowBuilder を使用しており、3 状態のボタンが必要なプログラムをコーディングしています。私は JToggleButtons を使用し、それらの 2 つの状態を 2 つ使用しましたが、3 つ目の状態を実装できません。私に何ができる?

PS私は3つのアイコン状態が欲しいです。

4

1 に答える 1

1

で使用されているコードを見ることができるかもしれませんcom.jidesoft.swing.TristateCheckBox:
を参照してくださいTristateCheckBox.java

から継承しJToggleButton、3 つの異なるアイコン状態があります。

/**
 * 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 {
于 2011-11-13T23:43:08.157 に答える