165 |
/* Size of the largest item in the comboBox |
/* Size of the largest item in the comboBox |
166 |
* This is package-private to avoid an accessor method. |
* This is package-private to avoid an accessor method. |
167 |
*/ |
*/ |
168 |
Dimension largestItemSize; |
Dimension displaySize; |
169 |
|
|
170 |
// It seems that JComboBox doesn't have a border set explicitely. So we just |
// It seems that JComboBox doesn't have a border set explicitely. So we just |
171 |
// paint the border everytime combo box is displayed. |
// paint the border everytime combo box is displayed. |
874 |
* |
* |
875 |
* @return dimensions of the largest item in the combo box. |
* @return dimensions of the largest item in the combo box. |
876 |
*/ |
*/ |
877 |
private Dimension getLargestItemSize() |
protected Dimension getDisplaySize() |
878 |
{ |
{ |
879 |
ComboBoxModel model = comboBox.getModel(); |
ComboBoxModel model = comboBox.getModel(); |
880 |
int numItems = model.getSize(); |
int numItems = model.getSize(); |
883 |
// return its default size |
// return its default size |
884 |
if (numItems == 0) |
if (numItems == 0) |
885 |
{ |
{ |
886 |
largestItemSize = getDefaultSize(); |
displaySize = getDefaultSize(); |
887 |
return largestItemSize; |
return displaySize; |
888 |
} |
} |
889 |
|
|
890 |
Dimension size = new Dimension(0, 0); |
Dimension size = new Dimension(0, 0); |
893 |
// size of the largest item in the combo box. |
// size of the largest item in the combo box. |
894 |
ListCellRenderer renderer = comboBox.getRenderer(); |
ListCellRenderer renderer = comboBox.getRenderer(); |
895 |
|
|
896 |
|
// FIXME: use the JComboBox.getPrototypeDisplayValue() if there is |
897 |
|
// one |
898 |
for (int i = 0; i < numItems; i++) |
for (int i = 0; i < numItems; i++) |
899 |
{ |
{ |
900 |
Object item = model.getElementAt(i); |
Object item = model.getElementAt(i); |
906 |
size = comp.getPreferredSize(); |
size = comp.getPreferredSize(); |
907 |
} |
} |
908 |
|
|
909 |
largestItemSize = size; |
displaySize = size; |
910 |
return largestItemSize; |
return displaySize; |
911 |
} |
} |
912 |
|
|
913 |
/** |
/** |
978 |
{ |
{ |
979 |
Dimension d = new Dimension(0, 0); |
Dimension d = new Dimension(0, 0); |
980 |
|
|
981 |
if (largestItemSize == null) |
if (displaySize == null) |
982 |
largestItemSize = getLargestItemSize(); |
displaySize = getDisplaySize(); |
983 |
|
|
984 |
// add size for the area that will display selected item |
// add size for the area that will display selected item |
985 |
d.width += largestItemSize.getWidth(); |
d.width += displaySize.getWidth(); |
986 |
d.height += largestItemSize.getHeight(); |
d.height += displaySize.getHeight(); |
987 |
|
|
988 |
// add size of the arrow button |
// add size of the arrow button |
989 |
d.width += arrowButtonWidth; |
d.width += arrowButtonWidth; |
1172 |
ComboBoxModel model = comboBox.getModel(); |
ComboBoxModel model = comboBox.getModel(); |
1173 |
ListCellRenderer renderer = comboBox.getRenderer(); |
ListCellRenderer renderer = comboBox.getRenderer(); |
1174 |
|
|
1175 |
if (largestItemSize == null) |
if (displaySize == null) |
1176 |
largestItemSize = getLargestItemSize(); |
displaySize = getDisplaySize(); |
1177 |
if (largestItemSize.width < getDefaultSize().width) |
if (displaySize.width < getDefaultSize().width) |
1178 |
largestItemSize.width = getDefaultSize().width; |
displaySize.width = getDefaultSize().width; |
1179 |
if (largestItemSize.height < getDefaultSize().height) |
if (displaySize.height < getDefaultSize().height) |
1180 |
largestItemSize.height = getDefaultSize().height; |
displaySize.height = getDefaultSize().height; |
1181 |
|
|
1182 |
comboBox.repaint(); |
comboBox.repaint(); |
1183 |
} |
} |
1191 |
public void intervalRemoved(ListDataEvent e) |
public void intervalRemoved(ListDataEvent e) |
1192 |
{ |
{ |
1193 |
// recalculate display size of the JComboBox. |
// recalculate display size of the JComboBox. |
1194 |
largestItemSize = getLargestItemSize(); |
displaySize = getDisplaySize(); |
1195 |
comboBox.repaint(); |
comboBox.repaint(); |
1196 |
} |
} |
1197 |
} |
} |