How to disable the popup of JComboBox?
I just used the JCelendar which use a JComboBox to display a date chooser. It is interesting that it disable the default list popup and use a date chooser dialog instead.
I have tried a lot (such as implementing the PopupMenuListener, setPopupVisible(false) and etc) but can not find the way to perfectly achieve that. And it seems that JCenlendar source code is not free. Can anyone help? Thanks.
[410 byte] By [
tmdfana] at [2007-11-26 17:02:03]

# 2
if you can deal with the flicker:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
public class DisablePopupTest {
public static void main(String[] args) {
final JComboBox c = new JComboBox();
c.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuCanceled(PopupMenuEvent e) {}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
System.out.println(e.getSource());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JPopupMenu m = new JPopupMenu("Menu");
m.add(new JMenuItem("TEST"));
m.setPreferredSize(new Dimension(200, 100));
m.show(c, 0, c.getHeight());
c.setPopupVisible(false);
}
});
}
});
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new FlowLayout());
f.getContentPane().add(c);
f.setSize(600, 400);
f.setVisible(true);
}
}