我想听听在CheckBoxListComboBox中单击Ok和Cancel按钮时发生的事件,有人知道如何注册Ok和Cancel按钮上的事件吗?如果事件注册是不可能的,我们可以重写我们自己的Ok和cancel按钮吗?
发布于 2014-08-22 23:12:54
似乎没有选择注册一个侦听器。但是,您可以重写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);
}
});
}
}https://stackoverflow.com/questions/25421513
复制相似问题