Please help
Try this:
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
public class Test {
static class ComboPanel extends JPanel {
public ComboPanel() {
final JComboBox combo = new JComboBox();
combo.setUI(new ComboBoxUI());
combo.addItem("One");
combo.addItem("Two");
combo.addItem("Three");
setLayout(new BorderLayout());
add(combo, BorderLayout.CENTER);
}
}
static class ComboBoxUI extends BasicComboBoxUI {
protected ComboPopup createPopup() {
return new ComboBoxPopup(comboBox);
}
}
static class ComboBoxPopup extends BasicComboPopup {
public ComboBoxPopup(JComboBox combo) {
super(combo);
}
protected MouseListener createListMouseListener() {
return new MouseAdapter() {
// TODO: add your implementation here
};
}
}
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new ComboPanel(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
Best regards,
Przemek
I guess I don't quite understand what sort of interaction you are trying
to achieve.
If you are talking about selecting an item with the mouse and then still
being able to scroll, then it doesn't seem to make much sense. After
all, if you want to scroll, why not just avoid clicking and scroll
instead?
--
Thomas A. Russ, USC/Information Sciences Institute