mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add ComboBoxWithWidePopup#getMinimumPopupWidth to simplify API (IDEA-CR-31064)
This commit is contained in:
@@ -69,12 +69,15 @@ public class ComboBoxWithWidePopup<E> extends JComboBox<E> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return original preferred size of JComboBox. E.g. its width naturally sets minimum
|
||||
* width of a wide popup as it's calculated as max of all pref sizes of combobox's items.
|
||||
* See {@link javax.swing.plaf.basic.BasicComboBoxUI#getDisplaySize()}.
|
||||
* @return minimum width of a popup that is wide enough to show all the combobox's items horizontally
|
||||
*/
|
||||
public Dimension getOriginalPreferredSize() {
|
||||
return super.getPreferredSize();
|
||||
public int getMinimumPopupWidth() {
|
||||
// Original preferred size of JComboBox is calculated as max of all pref sizes of combobox's items.
|
||||
// See javax.swing.plaf.basic.BasicComboBoxUI#getDisplaySize()
|
||||
//
|
||||
// Please note that "getPreferredSize().width" cannot be used as getPreferredSize might be overridden
|
||||
// to return a value different to "max of all pref sizes of comboBox's items".
|
||||
return super.getPreferredSize().width;
|
||||
}
|
||||
|
||||
private class AdjustingListCellRenderer implements ListCellRenderer<E> {
|
||||
|
||||
+2
-4
@@ -514,12 +514,10 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border, ErrorB
|
||||
public void show(Component invoker, int x, int y) {
|
||||
if (comboBox instanceof ComboBoxWithWidePopup) {
|
||||
Dimension popupSize = comboBox.getSize();
|
||||
// Can't use simply comboBox.getPreferredSize() as it can be overridden and implemented differently.
|
||||
// Here we need max of all pref sizes of comboBox's items.
|
||||
Dimension prefSize = ((ComboBoxWithWidePopup)comboBox).getOriginalPreferredSize();
|
||||
int minPopupWidth = ((ComboBoxWithWidePopup)comboBox).getMinimumPopupWidth();
|
||||
Insets insets = getInsets();
|
||||
|
||||
popupSize.width = Math.max(popupSize.width, prefSize.width);
|
||||
popupSize.width = Math.max(popupSize.width, minPopupWidth);
|
||||
popupSize.setSize(popupSize.width - (insets.right + insets.left), getPopupHeightForRowCount(comboBox.getMaximumRowCount()));
|
||||
|
||||
scroller.setMaximumSize(popupSize);
|
||||
|
||||
Reference in New Issue
Block a user