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); }
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()); }
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(); }
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; }
@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; }
@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; }
protected LayoutManager createLayoutManager() { return new BasicComboBoxUI.ComboBoxLayoutManager() { public void layoutContainer(Container parent) { layout(parent); } }; }
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; }
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; }
@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; } }); }
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)); } }
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; }