1 package fr.ifremer.quadrige2.ui.swing.common.plaf;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import javax.swing.*;
28 import javax.swing.plaf.ComponentUI;
29 import javax.swing.plaf.basic.BasicComboPopup;
30 import javax.swing.plaf.basic.ComboPopup;
31 import javax.swing.plaf.synth.SynthComboBoxUI;
32 import java.awt.*;
33
34
35
36
37
38
39 public class WiderSynthComboBoxUI extends SynthComboBoxUI {
40
41 private BasicComboPopup popup;
42
43
44
45
46 public static ComponentUI createUI(JComponent c) {
47 return new WiderSynthComboBoxUI();
48 }
49
50
51
52
53 @Override
54 protected ComboPopup createPopup() {
55 popup = new BasicComboPopup(comboBox) {
56
57 @Override
58 @SuppressWarnings("unchecked")
59 protected void configureList() {
60 list.setFont(comboBox.getFont());
61 list.setCellRenderer(comboBox.getRenderer());
62 list.setFocusable(false);
63 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
64 int selectedIndex = comboBox.getSelectedIndex();
65 if (selectedIndex == -1) {
66 list.clearSelection();
67 } else {
68 list.setSelectedIndex(selectedIndex);
69 list.ensureIndexIsVisible(selectedIndex);
70 }
71 installListListeners();
72 }
73
74 @Override
75 protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
76 return super.computePopupBounds(px, py, Math.max(comboBox.getPreferredSize().width, pw), ph);
77 }
78
79 };
80 popup.getAccessibleContext().setAccessibleParent(comboBox);
81 return popup;
82 }
83
84 public JList getPopupList() {
85 return popup.getList();
86 }
87 }