Search in sources :

Example 1 with BasicComboBoxUI

use of javax.swing.plaf.basic.BasicComboBoxUI in project android by JetBrains.

the class GradleEditorComboBoxEditor method getComboboxPopup.

@Nullable
private static ComboPopup getComboboxPopup(final JComboBox comboBox) {
    final ComboBoxUI ui = comboBox.getUI();
    ComboPopup popup = null;
    if (ui instanceof BasicComboBoxUI) {
        try {
            final Field popupField = BasicComboBoxUI.class.getDeclaredField("popup");
            popupField.setAccessible(true);
            popup = (ComboPopup) popupField.get(ui);
        } catch (NoSuchFieldException e1) {
            popup = null;
        } catch (IllegalAccessException e1) {
            popup = null;
        }
    }
    return popup;
}
Also used : Field(java.lang.reflect.Field) ComboPopup(javax.swing.plaf.basic.ComboPopup) BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI) ComboBoxUI(javax.swing.plaf.ComboBoxUI) BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BasicComboBoxUI

use of javax.swing.plaf.basic.BasicComboBoxUI in project java-swing-tips by aterai.

the class ComboCellRenderer method makeComboBox.

private static JComboBox<String> makeComboBox() {
    JComboBox<String> combo = new JComboBox<String>(new String[] { "Name 0", "Name 1", "Name 2" }) {

        @Override
        public void updateUI() {
            super.updateUI();
            setBorder(BorderFactory.createEmptyBorder());
            setUI(new BasicComboBoxUI() {

                @Override
                protected JButton createArrowButton() {
                    JButton button = super.createArrowButton();
                    button.setContentAreaFilled(false);
                    button.setBorder(BorderFactory.createEmptyBorder());
                    return button;
                }
            });
        //                 JTextField editor = (JTextField) getEditor().getEditorComponent();
        //                 editor.setBorder(BorderFactory.createEmptyBorder());
        //                 editor.setOpaque(true);
        //                 editor.setEditable(false);
        }
    };
    //combo.setEditable(true);
    return combo;
}
Also used : BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI)

Example 3 with BasicComboBoxUI

use of javax.swing.plaf.basic.BasicComboBoxUI in project java-swing-tips by aterai.

the class ComboCellRenderer method updateUI.

@Override
public void updateUI() {
    super.updateUI();
    setBorder(BorderFactory.createEmptyBorder());
    setUI(new BasicComboBoxUI() {

        @Override
        protected JButton createArrowButton() {
            button = super.createArrowButton();
            button.setContentAreaFilled(false);
            //button.setBackground(ComboCellRenderer.this.getBackground());
            button.setBorder(BorderFactory.createEmptyBorder());
            return button;
        }
    });
}
Also used : BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI)

Example 4 with BasicComboBoxUI

use of javax.swing.plaf.basic.BasicComboBoxUI in project intellij-community by JetBrains.

the class FixedComboBoxEditor method getComboboxPopup.

@Nullable
private static ComboPopup getComboboxPopup(final JComboBox comboBox) {
    final ComboBoxUI ui = comboBox.getUI();
    ComboPopup popup = null;
    if (ui instanceof BasicComboBoxUI) {
        popup = ReflectionUtil.getField(BasicComboBoxUI.class, ui, ComboPopup.class, "popup");
    }
    return popup;
}
Also used : ComboPopup(javax.swing.plaf.basic.ComboPopup) BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI) ComboBoxUI(javax.swing.plaf.ComboBoxUI) BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with BasicComboBoxUI

use of javax.swing.plaf.basic.BasicComboBoxUI in project java-swing-tips by aterai.

the class MainPanel method makePanel.

private static JPanel makePanel() {
    final JPanel p = new JPanel(new BorderLayout(5, 5));
    p.add(new JComboBox<>(new String[] { "aaaa", "bbbbbbbbbb", "ccccc" }));
    String[] items = { "JComboBox 11111:", "JComboBox 222:", "JComboBox 33:" };
    JComboBox<String> comboBox = new JComboBox<String>(items) {

        @Override
        public void updateUI() {
            super.updateUI();
            UIManager.put("ComboBox.squareButton", Boolean.FALSE);
            UIManager.put("ComboBox.background", p.getBackground());
            setUI(new BasicComboBoxUI() {

                @Override
                protected JButton createArrowButton() {
                    //.createArrowButton();
                    JButton button = new JButton();
                    button.setBorder(BorderFactory.createEmptyBorder());
                    button.setVisible(false);
                    return button;
                }
            });
            final ListCellRenderer<? super String> r = getRenderer();
            setRenderer(new ListCellRenderer<String>() {

                private final Color bgc = UIManager.getColor("ComboBox.background");

                @Override
                public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {
                    JLabel c = (JLabel) r.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    c.setHorizontalAlignment(SwingConstants.RIGHT);
                    if (isSelected) {
                        c.setForeground(list.getSelectionForeground());
                        c.setBackground(list.getSelectionBackground());
                    } else {
                        c.setForeground(list.getForeground());
                        c.setBackground(bgc);
                    }
                    return c;
                }
            });
            setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
            //setBackground(p.getBackground());
            setOpaque(false);
            setFocusable(false);
        }
    };
    p.add(comboBox, BorderLayout.WEST);
    p.setBorder(BorderFactory.createTitledBorder("JComboBox+JComboBox"));
    return p;
}
Also used : BasicComboBoxUI(javax.swing.plaf.basic.BasicComboBoxUI)

Aggregations

BasicComboBoxUI (javax.swing.plaf.basic.BasicComboBoxUI)6 ComboBoxUI (javax.swing.plaf.ComboBoxUI)2 ComboPopup (javax.swing.plaf.basic.ComboPopup)2 Nullable (org.jetbrains.annotations.Nullable)2 Field (java.lang.reflect.Field)1