javax.swing.plaf.basic.BasicComboBoxRenderer Java Examples
The following examples show how to use
javax.swing.plaf.basic.BasicComboBoxRenderer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DarculaComboBoxUI.java From consulo with Apache License 2.0 | 6 votes |
@Override protected ListCellRenderer createRenderer() { return new BasicComboBoxRenderer.UIResource() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (c instanceof JComponent) { final JComponent jc = (JComponent)c; if (index == -1) { jc.setOpaque(false); jc.setForeground(list.getForeground()); } else { jc.setOpaque(true); } } return c; } }; }
Example #2
Source File: ModernComboBoxUI.java From consulo with Apache License 2.0 | 6 votes |
@Override protected ListCellRenderer createRenderer() { return new BasicComboBoxRenderer.UIResource() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (c instanceof JComponent) { final JComponent jc = (JComponent)c; if (index == -1) { jc.setOpaque(false); jc.setForeground(list.getForeground()); } else { jc.setOpaque(true); } } return c; } }; }
Example #3
Source File: GenericToolbar.java From netbeans with Apache License 2.0 | 6 votes |
public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); if (PREFERRED_HEIGHT == -1) { GenericToolbar tb = new GenericToolbar(); tb.setBorder(getBorder()); tb.setBorderPainted(isBorderPainted()); tb.setRollover(isRollover()); tb.setFloatable(isFloatable()); Icon icon = Icons.getIcon(GeneralIcons.SAVE); tb.add(new JButton("Button", icon)); // NOI18N tb.add(new JToggleButton("Button", icon)); // NOI18N tb.add(new JTextField("Text")); // NOI18N JComboBox c = new JComboBox(); c.setEditor(new BasicComboBoxEditor()); c.setRenderer(new BasicComboBoxRenderer()); tb.add(c); tb.addSeparator(); PREFERRED_HEIGHT = tb.getSuperPreferredSize().height; } dim.height = getParent() instanceof JToolBar ? 1 : Math.max(dim.height, PREFERRED_HEIGHT); return dim; }
Example #4
Source File: GenericToolbar.java From visualvm with GNU General Public License v2.0 | 6 votes |
public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); if (PREFERRED_HEIGHT == -1) { GenericToolbar tb = new GenericToolbar(); tb.setBorder(getBorder()); tb.setBorderPainted(isBorderPainted()); tb.setRollover(isRollover()); tb.setFloatable(isFloatable()); Icon icon = Icons.getIcon(GeneralIcons.SAVE); tb.add(new JButton("Button", icon)); // NOI18N tb.add(new JToggleButton("Button", icon)); // NOI18N tb.add(new JTextField("Text")); // NOI18N JComboBox c = new JComboBox(); c.setEditor(new BasicComboBoxEditor()); c.setRenderer(new BasicComboBoxRenderer()); tb.add(c); tb.addSeparator(); PREFERRED_HEIGHT = tb.getSuperPreferredSize().height; } dim.height = getParent() instanceof JToolBar ? 1 : Math.max(dim.height, PREFERRED_HEIGHT); return dim; }
Example #5
Source File: Test7195179.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #6
Source File: ComboBoxTableCellEditor.java From consulo with Apache License 2.0 | 5 votes |
private ComboBoxTableCellEditor() { myComboBox.setRenderer(new BasicComboBoxRenderer()); myComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stopCellEditing(); } }); myPanel.add(myComboBox, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); }
Example #7
Source File: DataSourceSelectorGuiTest.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Test public void shouldDisplayNoSelected() { window.label(new GenericTypeMatcher<BasicComboBoxRenderer>(BasicComboBoxRenderer.class) { @Override protected boolean isMatching(BasicComboBoxRenderer component) { return true; } }).requireText(NO_DATA_SOURCE); }
Example #8
Source File: Test7195179.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #9
Source File: Test7195179.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #10
Source File: Test7195179.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #11
Source File: Test7195179.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #12
Source File: Test7195179.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #13
Source File: LookAndFeelsComboBox.java From FlatLaf with Apache License 2.0 | 5 votes |
@SuppressWarnings( "unchecked" ) public LookAndFeelsComboBox() { setRenderer( new BasicComboBoxRenderer() { @Override @SuppressWarnings( "rawtypes" ) public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) { value = (value != null) ? ((LookAndFeelInfo)value).getName() : UIManager.getLookAndFeel().getName(); return super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); } } ); }
Example #14
Source File: Test7195179.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #15
Source File: CreateAvdVisualPanel3.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
void readSettings() { defaultSdk = (AndroidSdk) wiz.getProperty(ANDROID_SDK); avdManager = (AvdManager) wiz.getProperty(AVD_MANAGER); selectedDevice = (Device) wiz.getProperty(DEVICE_SELECTED); selectedImage = (SystemImageDescription) wiz.getProperty(SYSTEM_IMAGE); initAvdName(); updateAvdId(); defaultSkinPath = defaultSdk.getSdkPath() + File.separator + "skins"; File skinFile = selectedDevice.getDefaultHardware().getSkinFile(); String skinPath = defaultSdk.getSdkPath() + File.separator + "skins" + File.separator + skinFile; skinCombo.setModel(new SkinsComboboxModel(new File(defaultSkinPath))); skinCombo.setSelectedItem(new File(skinPath)); skinCombo.setRenderer(new BasicComboBoxRenderer() { @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Templates. if ((component instanceof JLabel) && (value instanceof File)) { ((JLabel) component).setText(((File) value).getName()); } return component; } }); performanceGraphics.setSelectedItem(GpuMode.AUTO); avdName.getDocument().addDocumentListener(this); performanceCores.setModel(new javax.swing.SpinnerNumberModel(RECOMMENDED_NUMBER_OF_CORES, 1, MAX_NUMBER_OF_CORES, 1)); // initPlaystore(); initMemory(); }
Example #16
Source File: Test7195179.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #17
Source File: Test7195179.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #18
Source File: Test7195179.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #19
Source File: Test7195179.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #20
Source File: Test7195179.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #21
Source File: Test7195179.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { invokeAndWait(new Runnable() { @Override public void run() { Integer[] items = {null, 1, 2, 3}; JComboBox<Integer> combo = new JComboBox<>(items); JLabel label = new JLabel("choose:"); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); label.setLabelFor(combo); combo.setSelectedIndex(0); combo.setRenderer(new ListCellRenderer<Integer>() { private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); @Override public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) { return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); layout.setHorizontalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(label)) .addGroup(layout.createParallelGroup().addComponent(combo))); layout.setVerticalGroup(layout .createSequentialGroup() .addGroup(layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(label) .addComponent(combo))); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(panel); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.pack(); frame.setVisible(true); } }); }
Example #22
Source File: AvdHwProfile.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
/** * Creates new form AvdHwProfile */ public AvdHwProfile(Device device, DeviceManager deviceManager,boolean edit) { this.deviceManager = deviceManager; this.edit=edit; initComponents(); deviceType.setModel(new DefaultComboBoxModel<>(DeviceType.values())); if (device != null) { String tagId = device.getTagId(); initBootProperties(device); if (tagId == null) { deviceType.setSelectedItem(DeviceType.MOBILE); } else if (DeviceType.TV.id.equals(tagId)) { deviceType.setSelectedItem(DeviceType.TV); } else if (DeviceType.WEAR.id.equals(tagId)) { deviceType.setSelectedItem(DeviceType.WEAR); } if (edit) { deviceName.setText(device.getDisplayName()); deviceName.setEditable(false); }else{ deviceName.setText(String.format("%s (Edited)", device.getDisplayName())); } if (CreateAvdVisualPanel1.isTv(device)) { deviceType.setSelectedItem(DeviceType.TV); } else if (HardwareConfigHelper.isWear(device)) { deviceType.setSelectedItem(DeviceType.WEAR); } else { deviceType.setSelectedItem(DeviceType.MOBILE); } screenSize.setValue(device.getDefaultHardware().getScreen().getDiagonalLength()); Dimension dimension = device.getScreenSize(device.getDefaultState().getOrientation()); resolutionX.setValue(dimension.width); resolutionY.setValue(dimension.height); round.setSelected(device.isScreenRound()); ram.setValue(device.getDefaultHardware().getRam().getSizeAsUnit(Storage.Unit.MiB)); hwButt.setSelected(device.getDefaultHardware().getButtonType() == ButtonType.HARD); hwKeyb.setSelected(device.getDefaultHardware().getKeyboard() != Keyboard.NOKEY); List<State> states = device.getAllStates(); portrait.setSelected(false); landscape.setSelected(false); for (State state : states) { if (state.getOrientation().equals(ScreenOrientation.PORTRAIT)) { portrait.setSelected(true); } if (state.getOrientation().equals(ScreenOrientation.LANDSCAPE)) { landscape.setSelected(true); } } Navigation nav = device.getDefaultHardware().getNav(); switch (nav) { case NONAV: navigationStyle.setSelectedIndex(0); break; case DPAD: navigationStyle.setSelectedIndex(1); break; case TRACKBALL: navigationStyle.setSelectedIndex(2); break; case WHEEL: navigationStyle.setSelectedIndex(3); break; } cameraFront.setSelected(device.getDefaultHardware().getCamera(CameraLocation.FRONT) != null); cameraBack.setSelected(device.getDefaultHardware().getCamera(CameraLocation.BACK) != null); accelerometer.setSelected(device.getDefaultHardware().getSensors().contains(Sensor.ACCELEROMETER)); gyroscope.setSelected(device.getDefaultHardware().getSensors().contains(Sensor.GYROSCOPE)); gps.setSelected(device.getDefaultHardware().getSensors().contains(Sensor.GPS)); proximity.setSelected(device.getDefaultHardware().getSensors().contains(Sensor.PROXIMITY_SENSOR)); File skinFile = device.getDefaultHardware().getSkinFile(); AndroidSdk defaultSdk = AndroidSdkProvider.getDefaultSdk(); if (defaultSdk != null) { String skinPath = defaultSdk.getSdkPath() + File.separator + "skins"; skin.setModel(new SkinsComboboxModel(new File(skinPath))); } skin.setSelectedItem(skinFile); playstore.setSelected(device.hasPlayStore()); } else { deviceType.setSelectedItem(DeviceType.MOBILE); navigationStyle.setSelectedIndex(0); deviceName.setText(getUniqueId(null)); } skin.setRenderer(new BasicComboBoxRenderer() { @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Templates. if ((component instanceof JLabel) && (value instanceof File)) { ((JLabel) component).setText(((File) value).getName()); } return component; } }); }