public static void main(String... args) throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) { try { UIManager.setLookAndFeel(lafInfo.getClassName()); } catch (Exception e) { throw new RuntimeException(e); } MetalComboBoxUI ui = new MetalComboBoxUI(); ui.installUI(new JComboBox()); ui.getBaseline(new JComboBox(), 0, 0); ui.getBaseline(new JComboBox(), 1, 1); ui.getBaseline(new JComboBox(), 2, 2); ui.getBaseline(new JComboBox(), 3, 3); ui.getBaseline(new JComboBox(), 4, 4); } } }); }
public static void main(String... args) throws Exception { MetalComboBoxUI ui = new MetalComboBoxUI(); ui.installUI(new JComboBox()); ui.getBaseline(new JComboBox(), 0, 0); ui.getBaseline(new JComboBox(), 1, 1); ui.getBaseline(new JComboBox(), 2, 2); ui.getBaseline(new JComboBox(), 3, 3); ui.getBaseline(new JComboBox(), 4, 4); }
@Override public void updateUI() { ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this); if (cui instanceof MetalComboBoxUI) { cui = new MetalTreeComboBoxUI(); } else if (cui instanceof MotifComboBoxUI) { cui = new MotifTreeComboBoxUI(); } else if (cui instanceof WindowsComboBoxUI) { cui = new WindowsTreeComboBoxUI(); } setUI(cui); }
/** * Create new image combo box * * @param parent * newmodelwindow pare t * @param imagesName * names of the imates * @param imagesText * texts of the imates */ public ImageComboBox(NewModelWindow parent, String[] imagesName, String[] imagesText) { super(new BorderLayout()); this.parent = parent; // Load images images = new ImageIcon[imagesName.length]; Integer[] intArray = new Integer[imagesName.length]; for (int i = 0; i < imagesName.length; i++) { intArray[i] = new Integer(i); images[i] = UIUtil.loadResourceIcon(imagesName[i]); if (images[i] != null) { images[i].setDescription(imagesText[i]); } } // create JComboBox list = new JComboBox<Integer>(intArray); Color bg = (Color) UIManager.get("ComboBox.background"); Color fg = (Color) UIManager.get("ComboBox.foreground"); UIManager.put("ComboBox.selectionBackground", bg); UIManager.put("ComboBox.selectionForeground", fg); list.setUI(new MetalComboBoxUI()); list.setBackground(Color.WHITE); ComboBoxRenderer renderer = new ComboBoxRenderer(images, imagesText); renderer.setPreferredSize(new Dimension(200, 150)); list.setRenderer(renderer); list.setMaximumRowCount(3); list.addActionListener(this); // Lay out the demo. add(list, BorderLayout.PAGE_START); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
private static<T> void setComboBoxProperties(JComboBox<T> comboBox, ImageInfoReader imageInfoReader) { comboBox.setOpaque(false); comboBox.setBackground(ColorPalette.FOREGROUND_COLOR); comboBox.setForeground(ColorPalette.FOREGROUND_COLOR); comboBox.setFont(Fonts.FONT); comboBox.setUI(new MetalComboBoxUI() { @Override protected ComboPopup createPopup() { return new TiledImageComboPopup( comboBox, imageInfoReader ); } }); }