我如何能實現三態切換按鈕?我使用的是eclipse和windowBuilder,我編寫的程序必須具有三態按鈕。我用JToggleButtons和他們的兩個狀態兩個BU不能實現第三個狀態。我能做什麼?切換之間的三個狀態JToggleButton中
P.S.我想要三個圖標狀態。
我如何能實現三態切換按鈕?我使用的是eclipse和windowBuilder,我編寫的程序必須具有三態按鈕。我用JToggleButtons和他們的兩個狀態兩個BU不能實現第三個狀態。我能做什麼?切換之間的三個狀態JToggleButton中
P.S.我想要三個圖標狀態。
也許你可以看看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 {
我怎麼能得到這個? –
@ÖmerFarukAK:你的意思是你沒有訪問源代碼?請記住,這是一個起點,是您檢查和挑選好主意的代碼。基德-OSS,基德公共層(專業Swing組件,http://java.net/projects/jide-oss/)是Javadesktop的一個子項目,於2011年1月開始我要說的是,這個項目似乎有已經實施了你以後的事情。 – VonC
對不起,我看不到鏈接,但你已經寫好......我的錯。 –
對不起。我在錯誤的線程中粘貼了我的答案。我在想什麼!我刪了它。 – stratwine
根本不是...... :) –