Java 类javax.swing.plaf.basic.BasicComboBoxUI 实例源码

项目:swing-material    文件:MaterialComboBox.java   
public MaterialComboBox() {
    setModel(new DefaultComboBoxModel<T>());
    setRenderer(new FieldRenderer<T>(this));
    setUI(new BasicComboBoxUI() {
        @Override
        protected ComboPopup createPopup() {
            BasicComboPopup popup = new Popup(comboBox);
            popup.getAccessibleContext().setAccessibleParent(comboBox);
            return popup;
        }

        @Override
        protected JButton createArrowButton() {
            JButton button = new javax.swing.plaf.basic.BasicArrowButton(
                    javax.swing.plaf.basic.BasicArrowButton.SOUTH,
                    MaterialColor.TRANSPARENT,
                    MaterialColor.TRANSPARENT,
                    MaterialColor.TRANSPARENT,
                    MaterialColor.TRANSPARENT);
            button.setName("ComboBox.arrowButton");
            return button;
        }
    });
    setOpaque(false);
    setBackground(MaterialColor.TRANSPARENT);
}
项目:cn1    文件:PersistenceDelegateTest.java   
public void test_writeObject_javax_swing_DefaultListModel() {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
        byteArrayOutputStream));

    DefaultListModel model = new DefaultListModel();
    model.add(0, 1);
    model.add(1, 2);
    ListDataHandler listDataHandler = new BasicComboBoxUI().new ListDataHandler();
    model.addListDataListener(listDataHandler);

    encoder.writeObject(model);
    encoder.close();
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
            byteArrayOutputStream.toByteArray()));
    XMLDecoder decoder = new XMLDecoder(stream);
    DefaultListModel aModel = (DefaultListModel) decoder.readObject();
    assertEquals(model.getSize(), aModel.getSize());
}
项目:breakout    文件:JComboBoxFixture.java   
public static String readText(final JComboBox cb, final int index) {
    return new DoSwingR<String>() {
        @Override
        protected String doRun() {
            Object value = cb.getItemAt(index);
            try {
                BasicComboBoxUI ui = (BasicComboBoxUI) cb.getUI();
                Field popupField = ReflectionUtils.getField(ui.getClass(), "popup");
                popupField.setAccessible(true);
                ComboPopup popup = (ComboPopup) popupField.get(ui);
                JList list = popup.getList();
                ListCellRenderer renderer = list.getCellRenderer();
                Component rendComp = renderer.getListCellRendererComponent(popup.getList(), value, index, false,
                        false);
                return ComponentFixture.Common.readText(rendComp);
            } catch (Exception ex) {
            }
            return value.toString();
        }
    }.result();
}
项目:freeVM    文件:PersistenceDelegateTest.java   
public void test_writeObject_javax_swing_DefaultListModel() {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
        byteArrayOutputStream));

    DefaultListModel model = new DefaultListModel();
    model.add(0, 1);
    model.add(1, 2);
    ListDataHandler listDataHandler = new BasicComboBoxUI().new ListDataHandler();
    model.addListDataListener(listDataHandler);

    encoder.writeObject(model);
    encoder.close();
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
            byteArrayOutputStream.toByteArray()));
    XMLDecoder decoder = new XMLDecoder(stream);
    DefaultListModel aModel = (DefaultListModel) decoder.readObject();
    assertEquals(model.getSize(), aModel.getSize());
}
项目:semoss    文件:PlayTextField.java   
JList getListBox() {
    JList listBox;
    try {
        Field field = JComponent.class.getDeclaredField("ui");
        field.setAccessible(true);
        BasicComboBoxUI ui = (BasicComboBoxUI) field.get(comboBox);
        field = BasicComboBoxUI.class.getDeclaredField("listBox");
        field.setAccessible(true);
        listBox = (JList) field.get(ui);
    } catch (NoSuchFieldException nsfe) {
        throw new RuntimeException(nsfe);
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    }
    return listBox;
}
项目:semoss    文件:AutoComplete.java   
JList getListBox() {
    JList listBox;
    try {
        Field field = JComponent.class.getDeclaredField("ui");
        field.setAccessible(true);
        BasicComboBoxUI ui = (BasicComboBoxUI) field.get(comboBox);
        field = BasicComboBoxUI.class.getDeclaredField("listBox");
        field.setAccessible(true);
        listBox = (JList) field.get(ui);
    } catch (NoSuchFieldException nsfe) {
        throw new RuntimeException(nsfe);
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    }
    return listBox;
}
项目:intellij-ce-playground    文件:FixedComboBoxEditor.java   
@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;
}
项目:intellij-ce-playground    文件:UIUtil.java   
@Nullable
public static ComboPopup getComboBoxPopup(@NotNull JComboBox comboBox) {
  final ComboBoxUI ui = comboBox.getUI();
  if (ui instanceof BasicComboBoxUI) {
    return ReflectionUtil.getField(BasicComboBoxUI.class, ui, ComboPopup.class, "popup");
  }

  return null;
}
项目:PasswordSafe    文件:AgComboBoxUI.java   
protected LayoutManager createLayoutManager()
{
    return new BasicComboBoxUI.ComboBoxLayoutManager()
    {
        public void layoutContainer(Container parent)
        {
            layout(parent);
        }
    };
}
项目:java-swing-tips    文件:MainPanel.java   
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.setBorder(BorderFactory.createEmptyBorder());
        // ((JTextField) combo.getEditor().getEditorComponent()).setBorder(null);
        // ((JTextField) combo.getEditor().getEditorComponent()).setMargin(null);
        // combo.setBackground(Color.WHITE);
        // combo.setOpaque(true);
        // combo.setEditable(true);
        return combo;
    }
项目:java-swing-tips    文件:MainPanel.java   
private static <E> JComboBox<E> makeComboBox(ComboBoxModel<E> model) {
        JComboBox<E> combo = new JComboBox<E>(model) {
            @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.setBorder(BorderFactory.createEmptyBorder());
        // ((JTextField) combo.getEditor().getEditorComponent()).setBorder(null);
        // ((JTextField) combo.getEditor().getEditorComponent()).setMargin(null);
        // combo.setBackground(Color.WHITE);
        // combo.setOpaque(true);
        // combo.setEditable(true);
        return combo;
    }
项目:java-swing-tips    文件:MainPanel.java   
@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;
        }
    });
}
项目:jediterm    文件:UIUtil.java   
@Nullable
public static ComboPopup getComboBoxPopup(@NotNull JComboBox comboBox) {
    final ComboBoxUI ui = comboBox.getUI();
    if (ui instanceof BasicComboBoxUI) {
        return ReflectionUtil.getField(BasicComboBoxUI.class, ui, ComboPopup.class, "popup");
    }

    return null;
}
项目:libgdxcn    文件:GdxSetupUI.java   
private void uiStyle() {
    nameText.setCaretColor(Color.WHITE);
    packageText.setCaretColor(Color.WHITE);
    gameClassText.setCaretColor(Color.WHITE);
    destinationText.setCaretColor(Color.WHITE);
    sdkLocationText.setCaretColor(Color.WHITE);

    nameLabel.setForeground(Color.WHITE);
    packageLabel.setForeground(Color.WHITE);
    gameClassLabel.setForeground(Color.WHITE);
    destinationLabel.setForeground(Color.WHITE);
    sdkLocationLabel.setForeground(Color.WHITE);
    sdkLocationText.setDisabledTextColor(Color.BLACK);

    versionLabel.setForeground(new Color(255, 20, 20));
    UIManager.put("ComboBox.selectionBackground", new ColorUIResource(new Color(70, 70, 70)));
    UIManager.put("ComboBox.selectionForeground", new ColorUIResource(Color.WHITE));
    versionButton.updateUI();
    versionButton.setForeground(new Color(255, 255, 255));
    versionButton.setBackground(new Color(20, 20, 20));
    versionButton.setPrototypeDisplayValue("I am a prototype");
    versionButton.setUI(new BasicComboBoxUI() {
        @Override
        protected JButton createArrowButton () {
            return new BasicArrowButton(
                    BasicArrowButton.SOUTH,
                    new Color(0, 0, 0),
                    new Color(0, 0, 0),
                    new Color(100, 100, 100),
                    new Color(100, 100, 100));
        }
    });

    projectsLabel.setForeground(new Color(200, 20, 20));
    extensionsLabel.setForeground(new Color(200, 20, 20));

    subProjectsPanel.setOpaque(true);
    subProjectsPanel.setBackground(new Color(46, 46, 46));

    for (JPanel extensionPanel : extensionsPanels) {
        extensionPanel.setOpaque(true);
        extensionPanel.setBackground(new Color(46, 46, 46));
    }
}
项目:java-swing-tips    文件:MainPanel.java   
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() {
                    JButton button = new JButton(); //.createArrowButton();
                    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;
}