簡體   English   中英

確定並取消Jide CheckBoxListComboBox中的按鈕句柄

[英]Ok and cancel button handle in Jide CheckBoxListComboBox

單擊CheckBoxListComboBox中的“確定”和“取消”按鈕時,我想聽事件。有人知道如何注冊“確定”和“取消”按鈕上的事件嗎? 如果無法注冊事件,我們可以覆蓋自己的“確定”和“取消”按鈕嗎?

似乎沒有選擇注冊偵聽器。 但是,您可以重寫getDialogOKAction()getDialogCancelAction() 您還可以覆蓋createListChooserPanel()並在那里提供您自己的操作。

例如:

import java.awt.event.ActionEvent;
import javax.swing.*;
import com.jidesoft.combobox.CheckBoxListComboBox;

public class TestCheckboxList extends JPanel{
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {   
            public void run() {   
                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationByPlatform(true);

                String[] items = {"Item1", "Item2", "Item3"};

                frame.add(new CheckBoxListComboBox(items){
                    @Override
                    protected Action getDialogOKAction() {
                        return new AbstractAction() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                System.out.println("OK");
                            }
                        };
                    }

                    @Override
                    protected Action getDialogCancelAction() {
                        return new AbstractAction() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                System.out.println("Cancel");
                            }
                        };
                    }
                });

                frame.pack();

                frame.setVisible(true);
            }
        });
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM