List of usage examples for javax.swing JComboBox setEditor
@BeanProperty(expert = true, description = "The editor that combo box uses to edit the current value") public void setEditor(ComboBoxEditor anEditor)
JComboBox
field. From source file:ColorComboBoxEditor.java
public static void main(String args[]) { Color colors[] = { Color.RED, Color.BLUE, Color.BLACK, Color.WHITE }; JFrame frame = new JFrame("Editable JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JComboBox comboBox = new JComboBox(colors); comboBox.setEditable(true);/* www. jav a 2s . com*/ comboBox.setEditor(new ColorComboBoxEditor(Color.RED)); frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ColorComboBox.java
public static void main(String args[]) { Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow }; JFrame frame = new JFrame("Color JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final JComboBox comboBox = new JComboBox(colors); comboBox.setMaximumRowCount(5);//from www . ja va 2 s . c o m comboBox.setEditable(true); comboBox.setRenderer(new ColorCellRenderer()); Color color = (Color) comboBox.getSelectedItem(); ComboBoxEditor editor = new ColorComboBoxEditor(color); comboBox.setEditor(editor); contentPane.add(comboBox, BorderLayout.NORTH); final JLabel label = new JLabel(); label.setOpaque(true); label.setBackground((Color) comboBox.getSelectedItem()); contentPane.add(label, BorderLayout.CENTER); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color selectedColor = (Color) comboBox.getSelectedItem(); label.setBackground(selectedColor); } }; comboBox.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:com.anrisoftware.prefdialog.miscswing.validatingfields.ValidatingComboBoxEditor.java
/** * Decorates the combo-box as a validating combo-box field. * //from w w w .j a v a2s .co m * @param field * the {@link JComboBox}. * * @return the {@link ValidatingComboBoxEditor} editor. */ public static ValidatingComboBoxEditor decorate(JComboBox<?> field) { ValidatingComboBoxEditor editor = new ValidatingComboBoxEditor(); field.setEditor(editor); return editor; }
From source file:MainClass.java
public MainClass() { // Build a mapping from book titles to their entries for (int i = 0; i < items.length; i++) { itemMap.put(items[i].getTitle(), items[i]); }// w ww .j a v a 2 s .co m setLayout(new BorderLayout()); JComboBox bookCombo = new JComboBox(items); bookCombo.setEditable(true); bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[0])); bookCombo.setMaximumRowCount(4); bookCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!"); } }); bookCombo.setActionCommand("Hello"); add(bookCombo, BorderLayout.CENTER); }
From source file:Main.java
public Main() { // Build a mapping from book titles to their entries for (int i = 0; i < items.length; i++) { itemMap.put(items[i].getTitle(), items[i]); }/*from w w w . j a va 2 s .com*/ setLayout(new BorderLayout()); JComboBox bookCombo = new JComboBox(items); bookCombo.setEditable(true); bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[0])); bookCombo.setMaximumRowCount(4); bookCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!"); } }); bookCombo.setActionCommand("Hello"); add(bookCombo, BorderLayout.CENTER); }
From source file:EditableComboBox.java
public EditableComboBox() { // Build a mapping from book titles to their entries for (int i = 0; i < books.length; i++) { bookMap.put(books[i].getTitle(), books[i]); }/*from w w w. j a va 2 s .c o m*/ setLayout(new BorderLayout()); JComboBox bookCombo = new JComboBox(books); bookCombo.setEditable(true); bookCombo.setEditor(new ComboBoxEditorExample(bookMap, books[0])); bookCombo.setMaximumRowCount(4); bookCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!"); } }); bookCombo.setActionCommand("Hello"); add(bookCombo, BorderLayout.CENTER); }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static <T> JComboBox<T> createComboBox(T[] values, JFormattedTextField textField, DocumentListener... docListeners) { JComboBox<T> cbox = new JComboBox<T>(values); cbox.setUI(new IntelComboBoxUI()); FormattedComboBoxEditor editor = new FormattedComboBoxEditor(textField); cbox.setEditable(true);// ww w.java2 s .c o m cbox.setEditor(editor); // Get the text editor for this combo box final JTextComponent tc = (JTextComponent) cbox.getEditor().getEditorComponent(); // Initialize the document listeners for (DocumentListener docListener : docListeners) { tc.getDocument().addDocumentListener(docListener); } return cbox; }
From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java
private void init() { this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS)); this.setResizable(false); JPanel basePanel = new JPanel(); basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS)); basePanel.setBorder(/* w ww . j a v a 2 s . c o m*/ BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); registerCloseWindowKeyListener(basePanel); // sink for error messages MessageLabel errorField = new MessageLabel(); errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight())); errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); TwoComponentsPanel lineError = new TwoComponentsPanel(errorField, Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight()))); lineError.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineError); // character set JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset")); labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(labelCharset); JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray()); listCharset.setAlignmentX(Component.LEFT_ALIGNMENT); listCharset.setSelectedItem(swingConfig.getDefaultCharset()); listCharset.setEditable(true); listCharset.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); listCharset.addActionListener(new CharacterSetListener(errorField)); listCharset.setEditor(new CharacterSetEditor(errorField)); basePanel.add(listCharset); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // select the group selector JPanel selectorPanel = new JPanel(); selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT ); JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator")); selectorPanel.add(labelSelector); JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST); selectorBox.setSelectedItem(Character.toString(groupReference)); selectorBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox cbox = (JComboBox) event.getSource(); String indicator = (String) cbox.getSelectedItem(); groupReference = indicator.charAt(0); } }); selectorPanel.add(selectorBox); basePanel.add(selectorPanel); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // checkbox DO BACKUP JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup")); doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT); doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING); doBackupFlag.setSelected(replaceForm.isDoBackup()); doBackupFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { doBackup = ItemEvent.SELECTED == event.getStateChange(); backupFlagEvent = event; } }); basePanel.add(doBackupFlag); JTextField backupDirPathTextField = new JTextField(); backupDirPathTextField.setPreferredSize( new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight())); backupDirPathTextField.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); backupDirPathTextField.setText(backupDirectory.getPath()); backupDirPathTextField.setToolTipText(backupDirectory.getPath()); backupDirPathTextField.setEditable(false); JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse")); BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField, new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField), swingConfig.getLocalizer().localize("label.choose-backup-directory")); openBaseDirFileChooserButton.addActionListener(backupDirButtonListener); TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField, openBaseDirFileChooserButton); lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineBaseDir); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); JPanel fileInfoPanel = new JPanel(); fileInfoPanel .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), swingConfig.getLocalizer().localize("label.default-file-info"))); fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS)); JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column")); fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.add(fileInfoLabel); fileInfoPanel.add(Box.createHorizontalGlue()); JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing")); nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT); nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name()); nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING); fileInfoOptions.add(nothingRadio); fileInfoPanel.add(nothingRadio); JRadioButton readOnlyRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.read-only-warning")); readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT); readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name()); readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY); fileInfoOptions.add(readOnlyRadio); fileInfoPanel.add(readOnlyRadio); JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize")); sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT); sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name()); sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE); fileInfoOptions.add(sizeRadio); fileInfoPanel.add(sizeRadio); JCheckBox showPlainBytesFlag = new JCheckBox( " " + swingConfig.getLocalizer().localize("label.show-plain-bytes")); showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT); showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING); showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes()); showPlainBytesFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { showBytes = ItemEvent.SELECTED == event.getStateChange(); } }); fileInfoPanel.add(showPlainBytesFlag); JRadioButton lastModifiedRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.last-modified")); lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT); lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name()); lastModifiedRadio .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED); fileInfoOptions.add(lastModifiedRadio); fileInfoPanel.add(lastModifiedRadio); basePanel.add(fileInfoPanel); // buttons JPanel buttonPannel = new JPanel(); buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT); buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING)); // cancel JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SettingsDialog.this.dispose(); } }); buttonPannel.add(cancelButton); // save JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save")); saveButton.addActionListener(new SaveButtonListener()); buttonPannel.add(saveButton); this.getRootPane().setDefaultButton(saveButton); this.add(basePanel); this.add(buttonPannel); placeOnScreen(swingConfig.getScreenCenter()); }
From source file:org.springframework.richclient.factory.DefaultComponentFactory.java
public void configureForEnum(JComboBox comboBox, Class enumType) { Collection enumValues = getEnumResolver().getLabeledEnumSet(enumType); if (logger.isDebugEnabled()) { logger.debug("Populating combo box model with enums of type '" + enumType.getName() + "'; enums are [" + enumValues + "]"); }/*from w w w . jav a 2 s.c om*/ CompoundComparator comparator = new CompoundComparator(); comparator.addComparator(LabeledEnum.LABEL_ORDER); comparator.addComparator(new ComparableComparator()); comboBox.setModel(new ComboBoxListModel(new ArrayList(enumValues), comparator)); comboBox.setRenderer(new LabeledEnumListRenderer(messageSource)); comboBox.setEditor(new LabeledEnumComboBoxEditor(messageSource, comboBox.getEditor())); }