List of usage examples for javax.swing JComboBox getModel
public ComboBoxModel<E> getModel()
JComboBox
. From source file:Main.java
public void keyPressed(KeyEvent evt) { JComboBox cb = (JComboBox) evt.getSource(); int curIx = cb.getSelectedIndex(); char ch = evt.getKeyChar(); JComboBox.KeySelectionManager ksm = cb.getKeySelectionManager(); if (ksm != null) { // Determine if another item has the same prefix int ix = ksm.selectionForKey(ch, cb.getModel()); boolean noMatch = ix < 0; boolean uniqueItem = ix == curIx; // Display menu if no matching items or the if the selection is not unique if (noMatch || !uniqueItem) { cb.showPopup();//from w w w . j a v a 2s .c o m } } }
From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java
private boolean setSelectedString(JComboBox comboBox, String stringToSelect) { final ComboBoxModel model = comboBox.getModel(); int size = model.getSize(); for (int index = 0; index < size; index++) { if (model.getElementAt(index).toString().equals(stringToSelect)) { comboBox.setSelectedIndex(index); return true; }/* w w w . ja v a 2 s . c o m*/ } return false; }
From source file:de.fhg.iais.asc.ui.parts.TransformersPanel.java
/** * helper//from w w w . j ava 2s .c om */ private boolean setSelectedString(JComboBox comboBox, String stringToSelect) { final ComboBoxModel model = comboBox.getModel(); int size = model.getSize(); for (int index = 0; index < size; index++) { if (model.getElementAt(index).toString().equals(stringToSelect)) { comboBox.setSelectedIndex(index); return true; } } return false; }
From source file:au.org.ala.delta.editor.ui.image.ImageSettingsDialog.java
private void updateFromFont(Font font, JComboBox name, JComboBox size, JCheckBox bold, JCheckBox italic) { name.getModel().setSelectedItem(font.getFamily()); size.getModel().setSelectedItem(font.getSize()); bold.setSelected(font.isBold());//from w w w . j ava 2s.c om italic.setSelected(font.isItalic()); }
From source file:edu.ku.brc.specify.datamodel.busrules.AgentBusRules.java
/** * Enables/Disables both the control and the Label * @param id the id of the control//from www. j a v a 2s. co m * @param enabled enable it * @param value the value it should set * @param thisObj the main data object */ protected void enableFieldAndLabel(final String id, final boolean enabled, final String value, final Agent agent) { Component field = formViewObj.getCompById(id); if (field != null) { field.setEnabled(enabled); if (field instanceof TextFieldFromPickListTable) { String title = ""; PickListDBAdapterIFace adaptor = ((TextFieldFromPickListTable) field).getPickListAdapter(); if (adaptor != null) { for (PickListItemIFace pli : adaptor.getList()) { if (pli.getValue().equals(value)) { title = pli.getTitle(); break; } } ((TextFieldFromPickListTable) field).setText(title); } else { log.error("Adapter was null for id [" + id + "] on the Agent Form."); } return; } if (field instanceof JComboBox || field instanceof ValComboBox) { JComboBox<?> cbx = field instanceof ValComboBox ? ((ValComboBox) field).getComboBox() : (JComboBox<?>) field; int inx = -1; if (value != null) { AbstractListModel<?> model = (AbstractListModel<?>) cbx.getModel(); for (int i = 0; i < model.getSize(); i++) { Object item = model.getElementAt(i); if (item instanceof PickListItemIFace) { PickListItemIFace pli = (PickListItemIFace) item; if (pli.getValue().equals(value)) { inx = i; break; } } else if (item.toString().equals(value)) { inx = i; break; } } } //System.err.println("AgentBusRules - id "+id+" setting to "+inx); cbx.setSelectedIndex(inx); } else if (field instanceof JTextComponent) { ((JTextComponent) field).setText(value != null ? value : ""); } else if (field instanceof PartialDateUI) { PartialDateUI plugin = (PartialDateUI) field; plugin.setValue(agent, null); } else { log.debug("******** unhandled component type: " + field); } JLabel label = formViewObj.getLabelFor(field); if (label != null) { label.setEnabled(enabled); } } }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfControlPanel.java
private PanelBuilder buildMainPanel(PanelBuilder builder, CellConstraints cc) { JLabel jLabelIdInTheApeEACCPF = new JLabel(this.labels.getString("eaccpf.control.idintheapeeaccpf")); builder.add(jLabelIdInTheApeEACCPF, cc.xy(1, rowNb)); //extracted from dashboard implementation Random random = new Random(); String value = ""; // String mainagencycode = (this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode()!=null && this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue()!=null )?this.eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue():""; if (this.eaccpf.getControl().getRecordId().getValue() == null || this.eaccpf.getControl().getRecordId().getValue().isEmpty()) { int fakeId = random.nextInt(1000000000); value = Integer.toString(fakeId); // value = "eac_" + mainagencycode + "_" + Integer.toString(fakeId); } else {/*from w ww . j a va 2 s. com*/ value = this.eaccpf.getControl().getRecordId().getValue(); } JTextField jTextFieldIdInTheApeEACCPF = new JTextField(value); jTextFieldIdInTheApeEACCPF.setEnabled(false); //put like disabled, it's not editable builder.add(jTextFieldIdInTheApeEACCPF, cc.xy(3, rowNb)); this.idAutogeneratedControl = jTextFieldIdInTheApeEACCPF.getText(); //It's not shown because field is autogenerated and it's not editabled (eaccpf object has no access to this value by form) setNextRow(); JLabel jLabelLinkPersonResponsible = new JLabel( this.labels.getString("eaccpf.control.personinstitutionresponsiblefordescription")); builder.add(jLabelLinkPersonResponsible, cc.xy(1, rowNb)); String content = ""; if (StringUtils.isNotEmpty(responsible)) { content = responsible; } else if (this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() > 0 && this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent() != null && this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent().getContent() != null && !this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent().getContent().isEmpty()) { content = this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent() .get(this.eaccpf.getControl().getMaintenanceHistory().getMaintenanceEvent().size() - 1) .getAgent().getContent(); } else { content = MAINTENANCE_AGENT_HUMAN; } JTextField jTextFieldPersonResponsible = new JTextField(content); builder.add(jTextFieldPersonResponsible, cc.xy(3, rowNb)); this.personInstitutionResponsibleTextField = jTextFieldPersonResponsible; setNextRow(); JLabel jLabelIdentifierForPersonResponsible = new JLabel( this.labels.getString("eaccpf.control.identifierofinstitutionresponsible") + "*"); builder.add(jLabelIdentifierForPersonResponsible, cc.xy(1, rowNb)); content = eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue() != null ? eaccpf.getControl().getMaintenanceAgency().getAgencyCode().getValue() : ""; JTextField jTextFieldIdentifierForPersonResponsible = new JTextField(content); builder.add(jTextFieldIdentifierForPersonResponsible, cc.xy(3, rowNb)); this.idControl = jTextFieldIdentifierForPersonResponsible; setNextRow(); if (StringUtils.isEmpty(content)) { builder.add(createErrorLabel(this.labels.getString("eaccpf.control.error.emptyidentifier")), cc.xyw(1, this.rowNb, 3)); setNextRow(); } if (this.eaccpf.getControl().getOtherRecordId().isEmpty()) { OtherRecordId newOtherRecordId = new OtherRecordId(); newOtherRecordId.setLocalType(EacCpfPanel.LOCAL_TYPE_ORIGINAL); this.eaccpf.getControl().getOtherRecordId().add(newOtherRecordId); } List<OtherRecordId> otherRecordIds = this.eaccpf.getControl().getOtherRecordId(); this.localIdentifierForInstitution = new ArrayList<JTextField>(otherRecordIds.size()); this.listIdentifierType = new ArrayList<JTextField>(otherRecordIds.size()); for (OtherRecordId otherRecordId : otherRecordIds) { // Create element. JTextField jTextFieldLocalIdentifierPersonResponsible = new JTextField(otherRecordId.getContent()); JTextField jTextFieldIdentifierType = new JTextField(otherRecordId.getLocalType()); // Add elements to the list. this.localIdentifierForInstitution.add(jTextFieldLocalIdentifierPersonResponsible); this.listIdentifierType.add(jTextFieldIdentifierType); builder.addLabel(this.labels.getString("eaccpf.control.otherRecordIdentifier"), cc.xy(1, this.rowNb)); builder.add(jTextFieldLocalIdentifierPersonResponsible, cc.xy(3, this.rowNb)); this.setNextRow(); } JButton nextTabBtn = new ButtonTab(this.labels.getString("eaccpf.control.addlocalidentifier")); builder.add(nextTabBtn, cc.xy(1, this.rowNb)); nextTabBtn.addActionListener(new AddLocalIdentifier(eaccpf, tabbedPane, model)); setNextRow(); builder.addLabel(this.labels.getString("eaccpf.control.usedlanguagesandscriptsfordescription"), cc.xyw(1, this.rowNb, 7)); setNextRow(); builder.addLabel(labels.getString("eaccpf.commons.select.language") + "*" + ":", cc.xy(1, rowNb)); LanguageWithScript languageWithScript = new LanguageWithScript(firstLanguage, firstScript, labels); JComboBox<String> scriptBox = languageWithScript.getScriptBox(); //fix for script part, it's not selecting values boolean found = false; int size = scriptBox.getModel().getSize(); for (int i = 0; !found && i < size; i++) { String element = scriptBox.getModel().getElementAt(i); if (element != null && element.equalsIgnoreCase(firstScript)) { scriptBox.setSelectedIndex(i); found = true; } } //end fix for script part builder.add(languageWithScript.getLanguageBox(), cc.xy(3, rowNb)); this.languageFirst = languageWithScript.getLanguageBox(); builder.addLabel(labels.getString("eaccpf.control.selectascript") + "*" + ":", cc.xy(5, rowNb)); builder.add(languageWithScript.getScriptBox(), cc.xy(7, rowNb)); this.scriptFirst = languageWithScript.getScriptBox(); this.languageWithScript = languageWithScript; setNextRow(); return builder; }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
private void classComboActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_classComboActionPerformed {//GEN-HEADEREND:event_classComboActionPerformed JComboBox src = (JComboBox) evt.getSource(); this.parameters.setSpectralClass((String) (src.getModel().getSelectedItem())); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
private void lumClassComboActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_lumClassComboActionPerformed {//GEN-HEADEREND:event_lumClassComboActionPerformed JComboBox src = (JComboBox) evt.getSource(); this.parameters.setLuminosityClass((String) (src.getModel().getSelectedItem())); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
private void subclassComboActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_subclassComboActionPerformed {//GEN-HEADEREND:event_subclassComboActionPerformed JComboBox src = (JComboBox) evt.getSource(); this.parameters.setSpectralSubclass(Integer.parseInt((String) (src.getModel().getSelectedItem()))); }
From source file:com.alvermont.terraj.stargen.ui.StargenFrame.java
/** * Update a linked checkbox and combo box. The combo box will be enabled * if the checkbox is selected// w w w. j ava 2 s . co m * * @param component1 The checkbox that controls the combobox * @param component2 The combobox * @param state The new state to set the checkbox to * @param value The value to store in the combo box */ protected void updateCombo(JCheckBox component1, JComboBox<String> component2, boolean state, String value) { component1.setSelected(state); component2.setEnabled(state); component2.getModel().setSelectedItem(value); }