List of usage examples for javax.swing JComboBox setModel
@BeanProperty(description = "Model that the combo box uses to get data to display.") public void setModel(ComboBoxModel<E> aModel)
JComboBox
uses to obtain the list of items. From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java
private int FillPolymerComboBox(JComboBox comboBox, int id) { int result = -1; List<Polymer> polymers = this.polymerService.GetAllEntities(); if (polymers.size() > 0) { List<ComboBoxItem<Polymer>> polymerNames = polymers .stream().sorted(comparing(x -> x.getGrade())).map(x -> ComboBoxItemConvertor .ConvertToComboBoxItem(x, x.getGrade() + " / " + x.getCompany(), x.getId())) .collect(Collectors.toList()); Polymer polymer = new Polymer(); polymer.setId(0);/*from w w w .j a v a 2s. c o m*/ polymer.setCompany("- Select -"); polymerNames.add(0, new ComboBoxItem<Polymer>(polymer, polymer.getCompany(), polymer.getId())); ComboBoxItem[] polymerNamesArray = polymerNames.toArray(new ComboBoxItem[polymerNames.size()]); comboBox.setModel(new DefaultComboBoxModel(polymerNamesArray)); if (id != 0) { ComboBoxItem<Polymer> currentPolymerName = polymerNames.stream().filter(x -> x.getId() == id) .findFirst().get(); result = polymerNames.indexOf(currentPolymerName); } else { result = 0; } comboBox.setSelectedIndex(result); } return result; }
From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java
private int FillAdditiveComboBox(JComboBox comboBox, int id) { int result = -1; List<Additive> additives = this.additiveService.GetAllEntities(); if (additives.size() > 0) { List<ComboBoxItem<Additive>> additiveNames = additives .stream().sorted(comparing(x -> x.getGrade())).map(x -> ComboBoxItemConvertor .ConvertToComboBoxItem(x, x.getGrade() + " / " + x.getCompany(), x.getId())) .collect(Collectors.toList()); Additive additive = new Additive(); additive.setId(0);/*www.j av a 2s. c o m*/ additive.setCompany("- Select -"); additiveNames.add(0, new ComboBoxItem<Additive>(additive, additive.getCompany(), additive.getId())); ComboBoxItem[] additiveNamesArray = additiveNames.toArray(new ComboBoxItem[additiveNames.size()]); comboBox.setModel(new DefaultComboBoxModel(additiveNamesArray)); if (id != 0) { ComboBoxItem<Additive> currentAdditiveName = additiveNames.stream().filter(x -> x.getId() == id) .findFirst().get(); result = additiveNames.indexOf(currentAdditiveName); } else { result = 0; } comboBox.setSelectedIndex(result); } return result; }
From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java
private int FillStaffComboBox(JComboBox comboBox, int id, String jobType) { int result = -1; List<Staff> staffs = this.staffService.GetAllEntities(); if (!jobType.equals("")) { staffs = staffs.stream().filter(x -> x.getJobType().equals(jobType)).collect(Collectors.toList()); }//from w ww. ja v a 2 s . c om if (staffs.size() > 0) { List<ComboBoxItem<Staff>> staffNames = staffs.stream() .sorted(comparing(x -> x.getJobType() + " " + x.getName())).map(x -> ComboBoxItemConvertor .ConvertToComboBoxItem(x, x.getJobType() + " " + x.getName(), x.getId())) .collect(Collectors.toList()); Staff staff = new Staff(); staff.setId(0); staff.setName("- Select -"); staffNames.add(0, new ComboBoxItem<Staff>(staff, staff.getName(), staff.getId())); ComboBoxItem[] staffNamesArray = staffNames.toArray(new ComboBoxItem[staffNames.size()]); comboBox.setModel(new DefaultComboBoxModel(staffNamesArray)); if (id != 0) { ComboBoxItem<Staff> currentStaffName = staffNames.stream().filter(x -> x.getId() == id).findFirst() .get(); result = staffNames.indexOf(currentStaffName); } else { result = 0; } comboBox.setSelectedIndex(result); } return result; }
From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java
private int FillEntryComboBox(JComboBox comboBox, int id) { int result = -1; List<Entry> allEntrys = this.entryService.GetAllEntities(); if (allEntrys.size() > 0) { List<Entry> entrys = allEntrys.stream().filter(x -> x.getInUse().equals("YES")) .collect(Collectors.toList()); if (entrys.size() > 0) { List<ComboBoxItem<Entry>> entryNames = entrys.stream().sorted(comparing(x -> x.getCreateDate())) .map(x -> ComboBoxItemConvertor.ConvertToComboBoxItem(x, (x.getMachineId() != null ? x.getMachineId().getMachineNo() : "") + "/" + (x.getProductId() != null ? x.getProductId().getCode() : ""), x.getId()))/* w ww . ja v a 2 s. com*/ .collect(Collectors.toList()); Entry entry = new Entry(); entry.setId(0); entry.setShift("- Select -"); entryNames.add(0, new ComboBoxItem<Entry>(entry, entry.getShift(), entry.getId())); ComboBoxItem[] entryNamesArray = entryNames.toArray(new ComboBoxItem[entryNames.size()]); comboBox.setModel(new DefaultComboBoxModel(entryNamesArray)); if (id != 0) { ComboBoxItem<Entry> currentEntryName = entryNames.stream().filter(x -> x.getId() == id) .findFirst().get(); result = entryNames.indexOf(currentEntryName); this.currentEntry = ((ComboBoxItem<Entry>) comboBox.getSelectedItem()).getItem(); } else { result = 0; } comboBox.setSelectedIndex(result); } } return result; }
From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java
private int FillEmbossingComboBox(JComboBox comboBox, Integer id, String type) { int result = -1; List<Embossing> embossings = this.embossingService.GetAllEntities(); if (!type.equals("")) { embossings = embossings.stream().filter(x -> x.getType().equals(type)).collect(Collectors.toList()); }//w ww . j a va2 s . c o m if (embossings.size() > 0) { List<ComboBoxItem<Embossing>> embossingNames = embossings.stream() .sorted(comparing(x -> x.getType() + " " + x.getName())).map(x -> ComboBoxItemConvertor .ConvertToComboBoxItem(x, x.getType() + " " + x.getName(), x.getId())) .collect(Collectors.toList()); Embossing embossing = new Embossing(); embossing.setId(0); embossing.setName("- Select -"); embossingNames.add(0, new ComboBoxItem<Embossing>(embossing, embossing.getName(), embossing.getId())); ComboBoxItem[] embossingNamesArray = embossingNames.toArray(new ComboBoxItem[embossingNames.size()]); comboBox.setModel(new DefaultComboBoxModel(embossingNamesArray)); if (id != 0) { ComboBoxItem<Embossing> currentEmbossingName = embossingNames.stream().filter(x -> x.getId() == id) .findFirst().get(); result = embossingNames.indexOf(currentEmbossingName); } else { result = 0; } comboBox.setSelectedIndex(result); } return result; }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Staff() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***/*from w ww . java2 s. c om*/ * ____ _ __ __ * / ___|| |_ __ _ / _|/ _| * \___ \| __/ _` | |_| |_ * ___) | || (_| | _| _| * |____/ \__\__,_|_| |_| * */ JPanel pnlTraining = new JPanel(new BorderLayout()); final JButton btnTrainings = GUITools.createHyperlinkButton("opde.controlling.staff.training", null, null); Pair<LocalDate, LocalDate> minmax = TrainingTools.getMinMax(); btnTrainings.setEnabled(minmax != null); final JComboBox cmbYears = new JComboBox(); if (minmax == null) { cmbYears.setModel(new DefaultComboBoxModel()); } else { ArrayList<Integer> years = new ArrayList<>(); for (int year = minmax.getSecond().getYear(); year >= minmax.getFirst().getYear(); year--) { years.add(year); } cmbYears.setModel(SYSTools.list2cmb(years)); cmbYears.setSelectedIndex(0); } btnTrainings.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { SYSFilesTools.print( TrainingTools.getTraining2Attendees((Integer) cmbYears.getSelectedItem()), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlTraining.add(btnTrainings, BorderLayout.WEST); pnlTraining.add(cmbYears, BorderLayout.EAST); pnlContent.add(pnlTraining); return pnlContent; }
From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipTab.java
/** * Refresh the list of ObjEntity targets. Also refresh the table in case some * ObjRelationships were deleted.// w w w . j a v a 2 s . c o m */ private void reloadEntityList(EntityEvent e) { if (e.getSource() != this) { return; } // If current model added/removed, do nothing. ObjEntity entity = mediator.getCurrentObjEntity(); if (entity == e.getEntity() || entity == null) { return; } TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET); DefaultCellEditor editor = (DefaultCellEditor) col.getCellEditor(); JComboBox combo = (JComboBox) editor.getComponent(); combo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap())); combo.setModel(new DefaultComboBoxModel(createObjEntityComboModel())); ObjRelationshipTableModel model = (ObjRelationshipTableModel) table.getModel(); model.fireTableDataChanged(); }
From source file:org.eclipse.wb.internal.swing.preferences.laf.LafPreferencePage.java
/** * Creates {@link EmbeddedSwingComposite} with some Swing components to show it using different * LAFs./*w w w . j av a 2s . co m*/ */ private void createPreviewArea(Group previewGroup) { try { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); EmbeddedSwingComposite awtComposite = new EmbeddedSwingComposite(previewGroup, SWT.NONE) { @Override protected JComponent createSwingComponent() { // create the JRootPane JRootPane rootPane = new JRootPane(); { JMenuBar menuBar = new JMenuBar(); rootPane.setJMenuBar(menuBar); { JMenu mnFile = new JMenu(Messages.LafPreferencePage_previewFile); menuBar.add(mnFile); { JMenuItem mntmNew = new JMenuItem(Messages.LafPreferencePage_previewNew); mnFile.add(mntmNew); } { JMenuItem mntmExit = new JMenuItem(Messages.LafPreferencePage_previewExit); mnFile.add(mntmExit); } } { JMenu mnView = new JMenu(Messages.LafPreferencePage_previewView); menuBar.add(mnView); { JMenuItem mntmCommon = new JMenuItem(Messages.LafPreferencePage_previewCommon); mnView.add(mntmCommon); } } } GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0E-4 }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0E-4 }; rootPane.getContentPane().setLayout(gridBagLayout); { JLabel lblLabel = new JLabel(Messages.LafPreferencePage_previewLabel); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.gridx = 0; gbc.gridy = 0; rootPane.getContentPane().add(lblLabel, gbc); } { JButton btnPushButton = new JButton(Messages.LafPreferencePage_previewButton); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 0; rootPane.getContentPane().add(btnPushButton, gbc); } { JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] { Messages.LafPreferencePage_previewCombo, "ComboBox Item 1", "ComboBox Item 2" })); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 1; rootPane.getContentPane().add(comboBox, gbc); } { JRadioButton rdbtnRadioButton = new JRadioButton(Messages.LafPreferencePage_previewRadio); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 1; rootPane.getContentPane().add(rdbtnRadioButton, gbc); } { JCheckBox chckbxCheckbox = new JCheckBox(Messages.LafPreferencePage_previewCheck); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 5); gbc.gridx = 0; gbc.gridy = 2; rootPane.getContentPane().add(chckbxCheckbox, gbc); } { JTextField textField = new JTextField(); textField.setText(Messages.LafPreferencePage_previewTextField); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 1; gbc.gridy = 2; rootPane.getContentPane().add(textField, gbc); } return rootPane; } }; awtComposite.populate(); // restore current laf UIManager.put("ClassLoader", currentLookAndFeel.getClass().getClassLoader()); UIManager.setLookAndFeel(currentLookAndFeel); } catch (Throwable e) { DesignerPlugin.log(e); } }
From source file:org.netbeans.jcode.rest.controller.RESTPanel.java
private void setPackageType(JComboBox comboBox) { comboBox.setRenderer(PackageView.listRenderer()); ComboBoxModel model = PackageView.createListView(sourceGroup); if (model.getSize() > 0) { model.setSelectedItem(model.getElementAt(0)); }/* ww w . j a va 2 s . c o m*/ comboBox.setModel(model); addChangeListener(comboBox); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java
/** * Populates the JComboBox with the items provided adding hover tooltips, * selecting the specified item and attaching the listener. * /*from w ww .ja v a2 s. com*/ * @param comboBox The JComboBox to populate * @param listItems The items to populate the box with * @param select The item to select in the JComboBox * @param itemListener An item listener to add for the JComboBox */ private void displayItems(JComboBox comboBox, List<DataNode> listItems, DataNode select, ItemListener itemListener) { if (comboBox == null || listItems == null) return; //Only add the item the user can actually select if (itemListener != null) comboBox.removeItemListener(itemListener); comboBox.removeAllItems(); List<String> tooltips = new ArrayList<String>(listItems.size()); List<String> lines; ExperimenterData exp; SelectableComboBoxModel model = new SelectableComboBoxModel(); Selectable<DataNode> selected = null; GroupData group = getSelectedGroup(); ExperimenterData user = getSelectedUser(); long userID = -1; if (user != null) userID = user.getId(); ExperimenterData loggedIn = ImporterAgent.getUserDetails(); boolean isAdmin = ImporterAgent.isAdministrator(); long loggedInID = loggedIn.getId(); boolean userIsAdmin = isAdmin(userID); for (DataNode node : listItems) { exp = getExperimenter(node.getOwner()); lines = new ArrayList<String>(); if (exp != null) { lines.add("<b>Owner: </b>" + EditorUtil.formatExperimenter(exp)); } lines.addAll(UIUtilities.wrapStyleWord(node.getFullName())); tooltips.add(UIUtilities.formatToolTipText(lines)); boolean selectable = true; if (!node.isDefaultNode()) { selectable = canLink(node.getDataObject(), userID, group, loggedInID, isAdmin, userIsAdmin); } Selectable<DataNode> comboBoxItem = new Selectable<DataNode>(node, selectable); if (select != null && node.getDataObject().getId() == select.getDataObject().getId()) selected = comboBoxItem; model.addElement(comboBoxItem); } ComboBoxToolTipRenderer renderer = createComboboxRenderer(); renderer.setTooltips(tooltips); comboBox.setModel(model); comboBox.setRenderer(renderer); if (selected != null) comboBox.setSelectedItem(selected); if (itemListener != null) comboBox.addItemListener(itemListener); }