List of usage examples for javax.swing JComboBox addItem
public void addItem(E item)
From source file:Interface.Stats.java
/** * * @param f //from www .j a v a 2 s . c o m */ private Stats(JFrame f) { // On initialise les boutons JButton valider = new JButton("Valider"); JButton retour = new JButton("Retour"); JComboBox combo = new JComboBox(); // On initialise et remplit la combobox combo.setPreferredSize(new Dimension(400, 30)); combo.addItem("Nombre de patient par service"); combo.addItem("Salaire moyen des employs"); combo.addItem("Nombre d'intervention par mdecin"); // On initialise les JLabels JLabel texte = new JLabel("Veuillez selectionner la requete envoyer"); // On change le bouton de forme valider.setPreferredSize(new Dimension(200, 30)); valider.setOpaque(false); retour.setPreferredSize(new Dimension(200, 30)); retour.setOpaque(false); // On initialise les Jpanels p1 = new JPanel(); p1.setPreferredSize(new Dimension(600, 100)); p1.add(texte); p1.setOpaque(false); p2 = new JPanel(); p2.add(combo); p2.setOpaque(false); p4 = new JPanel(); p4.add(retour); p4.add(valider); p4.setOpaque(false); // Gestion des boutons retour.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Accueil.getFenetre(f); } }); valider.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (combo.getSelectedItem().equals("Nombre de patient par service")) { System.out.println( "Nb de patients en REA : " + Connexion.getInstance().nb_malade_services("\"REA\"")); System.out.println( "Nb de patients en ORL : " + Connexion.getInstance().nb_malade_services("\"ORL\"")); System.out.println( "Nb de patients en CHG : " + Connexion.getInstance().nb_malade_services("\"CHG\"")); // new Camembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\"")); JPanel panel_camemb = Camembert.cCamembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\"")); ; f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background f.add(p1); f.add(p2); f.add(p4); f.add(panel_camemb); f.setVisible(true); } else if (combo.getSelectedItem().equals("Salaire moyen des employs")) { JLabel jf_doc, jf_inf, jf_emp; JTextField jtf_doc, jtf_inf, jtf_emp; JPanel p5, p6, p7; // On initialise les JF jf_doc = new JLabel("Salaire moyen des docteurs"); jf_inf = new JLabel("Salaire moyen des infirmiers"); jf_emp = new JLabel("Salaire moyen de tous les employs"); // On initialise les JTF jtf_doc = new JTextField(); jtf_doc.setPreferredSize(new Dimension(200, 30)); jtf_doc.setText(Float.toString(Connexion.getInstance().moyenne_salaired()) + " "); jtf_inf = new JTextField(); jtf_inf.setPreferredSize(new Dimension(200, 30)); jtf_inf.setText(Float.toString((Connexion.getInstance().moyenne_salairei())) + " "); jtf_emp = new JTextField(); jtf_emp.setPreferredSize(new Dimension(160, 30)); jtf_emp.setText(Float.toString((Connexion.getInstance().moyenne_salaire())) + " "); // On cre les JPanels p5 = new JPanel(); p5.add(jf_doc); p5.add(jtf_doc); p5.setOpaque(false); p6 = new JPanel(); p6.add(jf_inf); p6.add(jtf_inf); p6.setOpaque(false); p7 = new JPanel(); p7.add(jf_emp); p7.add(jtf_emp); p7.setOpaque(false); f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background f.add(p1); f.add(p2); f.add(p4); f.add(p5); f.add(p6); f.add(p7); f.setVisible(true); f.setSize(new Dimension(600, 600)); } else if (combo.getSelectedItem().equals("Nombre d'intervention par mdecin")) { ArrayList liste = null; try { // ICI !!!!!!!!!! liste = Connexion.getInstance().reporting( "SELECT e.nom , COUNT(d.no_docteur) FROM hospitalisation h, docteur d , employe e WHERE (h.no_docteur= d.no_docteur) AND e.no_employe = d.no_docteur GROUP BY e.nom"); } catch (SQLException ex) { Logger.getLogger(Stats.class.getName()).log(Level.SEVERE, null, ex); } if (liste != null) { JPanel panel_camemb = Camembert.cCamembert(f, liste); f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background f.add(p1); f.add(p2); f.add(p4); f.add(panel_camemb); f.setVisible(true); } } } }); }
From source file:io.github.jeddict.jpa.modeler.initializer.JPAModelerUtil.java
public static void initEntityModel(javax.swing.JComboBox entityComboBox, EntityMappings entityMappings) { entityComboBox.removeAllItems();//ww w . j ava 2 s . c om entityComboBox.addItem(new ComboBoxValue(null, "")); entityMappings.getEntity().forEach((entity) -> { entityComboBox.addItem(new ComboBoxValue(entity, entity.getClazz())); }); }
From source file:Vista.CuentasCobrar.java
private void insertarCB(JComboBox seleccion, ArrayList<String> lista) { lista.stream().forEach((s) -> {// ww w . j av a 2 s . c om if (s.contains(";")) { String[] temp = s.split(";"); seleccion.addItem(temp[temp.length - 1]); } else { seleccion.addItem(s); } }); }
From source file:com.haulmont.cuba.desktop.LoginDialog.java
protected void initLocales(JComboBox<String> localeCombo) { String currLocale = loginProperties.loadLastLocale(); if (StringUtils.isBlank(currLocale)) { currLocale = messages.getTools().localeToString(resolvedLocale); }/*from w ww. j a v a 2 s.co m*/ String selected = null; for (Map.Entry<String, Locale> entry : locales.entrySet()) { localeCombo.addItem(entry.getKey()); if (messages.getTools().localeToString(entry.getValue()).equals(currLocale)) selected = entry.getKey(); } if (selected == null) selected = locales.keySet().iterator().next(); localeCombo.setSelectedItem(selected); }
From source file:edu.harvard.mcz.imagecapture.SpecimenPartAttributeDialog.java
private void init() { thisDialog = this; setBounds(100, 100, 820, 335);/*from w w w . j a v a2s. c o m*/ getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); panel.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { JLabel lblAttributeType = new JLabel("Attribute Type"); panel.add(lblAttributeType, "2, 2, right, default"); } { comboBoxType = new JComboBox(); comboBoxType.setModel(new DefaultComboBoxModel( new String[] { "caste", "scientific name", "sex", "life stage", "part association" })); comboBoxType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = comboBoxType.getSelectedItem().toString(); if (item != null) { comboBoxValue.setEditable(false); if (item.equals("scientific name")) { comboBoxValue.setEditable(true); } if (item.equals("sex")) { comboBoxValue.setModel(new DefaultComboBoxModel(Sex.getSexValues())); } if (item.equals("life stage")) { comboBoxValue.setModel(new DefaultComboBoxModel(LifeStage.getLifeStageValues())); } if (item.equals("caste")) { comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues())); } if (item.equals("part association")) { comboBoxValue .setModel(new DefaultComboBoxModel(PartAssociation.getPartAssociationValues())); } } } }); panel.add(comboBoxType, "4, 2, fill, default"); } { JLabel lblValue = new JLabel("Value"); panel.add(lblValue, "2, 4, right, default"); } { comboBoxValue = new JComboBox(); comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues())); panel.add(comboBoxValue, "4, 4, fill, default"); } { JLabel lblUnits = new JLabel("Units"); panel.add(lblUnits, "2, 6, right, default"); } { textFieldUnits = new JTextField(); panel.add(textFieldUnits, "4, 6, fill, default"); textFieldUnits.setColumns(10); } { JLabel lblRemarks = new JLabel("Remarks"); panel.add(lblRemarks, "2, 8, right, default"); } contentPanel.setLayout(new BorderLayout(0, 0)); contentPanel.add(panel, BorderLayout.WEST); { textFieldRemarks = new JTextField(); panel.add(textFieldRemarks, "4, 8, fill, default"); textFieldRemarks.setColumns(10); } { JButton btnAdd = new JButton("Add"); btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SpecimenPartAttribute newAttribs = new SpecimenPartAttribute(); newAttribs.setAttributeType(comboBoxType.getSelectedItem().toString()); newAttribs.setAttributeValue(comboBoxValue.getSelectedItem().toString()); newAttribs.setAttributeUnits(textFieldUnits.getText()); newAttribs.setAttributeRemark(textFieldRemarks.getText()); newAttribs.setSpecimenPartId(parentPart); newAttribs.setAttributeDeterminer(Singleton.getSingletonInstance().getUserFullName()); parentPart.getAttributeCollection().add(newAttribs); SpecimenPartAttributeLifeCycle sls = new SpecimenPartAttributeLifeCycle(); try { sls.attachDirty(newAttribs); } catch (SaveFailedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ((AbstractTableModel) table.getModel()).fireTableDataChanged(); } }); panel.add(btnAdd, "4, 10"); } try { JLabel lblNewLabel = new JLabel(parentPart.getSpecimenId().getBarcode() + ":" + parentPart.getPartName() + " " + parentPart.getPreserveMethod() + " (" + parentPart.getLotCount() + ") Right click on table to edit attributes."); contentPanel.add(lblNewLabel, BorderLayout.NORTH); } catch (Exception e) { JLabel lblNewLabel = new JLabel("No Specimen"); contentPanel.add(lblNewLabel, BorderLayout.NORTH); } JComboBox comboBox = new JComboBox(); comboBox.addItem("caste"); JComboBox comboBox1 = new JComboBox(); for (int i = 0; i < Caste.getCasteValues().length; i++) { comboBox1.addItem(Caste.getCasteValues()[i]); } JScrollPane scrollPane = new JScrollPane(); table = new JTable(new SpecimenPartsAttrTableModel( (Collection<SpecimenPartAttribute>) parentPart.getAttributeCollection())); //table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox)); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnRow = ((JTable) e.getComponent()).getSelectedRow(); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnRow = ((JTable) e.getComponent()).getSelectedRow(); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); popupMenu = new JPopupMenu(); JMenuItem mntmCloneRow = new JMenuItem("Edit Row"); mntmCloneRow.setMnemonic(KeyEvent.VK_E); mntmCloneRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Launch a dialog to edit the selected row. SpecimenPartAttribEditDialog popup = new SpecimenPartAttribEditDialog( ((SpecimenPartsAttrTableModel) table.getModel()).getRowObject(clickedOnRow)); popup.setVisible(true); } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisDialog, "Failed to edit a part attribute row. " + ex.getMessage()); } } }); popupMenu.add(mntmCloneRow); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.setMnemonic(KeyEvent.VK_D); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (clickedOnRow >= 0) { ((SpecimenPartsAttrTableModel) table.getModel()).deleteRow(clickedOnRow); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisDialog, "Failed to delete a part attribute row. " + ex.getMessage()); } } }); popupMenu.add(mntmDeleteRow); // TODO: Enable controlled value editing of selected row. // table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox1)); scrollPane.setViewportView(table); contentPanel.add(scrollPane, BorderLayout.EAST); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton.grabFocus(); thisDialog.setVisible(false); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { thisDialog.setVisible(false); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } }
From source file:Import.pnl_import_vcf.java
public void setMapTable(JTable table, DefaultTableModel model, String[] selectedFamilies, String[] selectedTableFamilies) { model.setRowCount(0);//from ww w .jav a 2 s . c om model.addColumn("Import Column"); model.addColumn("Map to"); TableColumn sportColumn = table.getColumnModel().getColumn(1); JComboBox comboBox = new JComboBox(); for (String a : selectedFamilies) { comboBox.addItem(a); } sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); for (String b : selectedTableFamilies) { String[] tmp = new String[1]; tmp[0] = b; model.addRow(tmp); } }
From source file:grafix.telas.TelaComparativos.java
private void popularCombo(JComboBox combo) { removerListener(combo);// w w w . ja v a2s .com combo.removeAllItems(); Vector<Acao> acoes = Controle.getCarteira().getAcoes(); for (Acao a : acoes) { combo.addItem(a); } adicionarListener(combo); }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_demand.java
public static void createLinkDemandGUI(final NetworkElementType networkElementType, final IVisualizationCallback callback) { final NetPlan netPlan = callback.getDesign(); final JComboBox originNodeSelector = new WiderJComboBox(); final JComboBox destinationNodeSelector = new WiderJComboBox(); for (Node node : netPlan.getNodes()) { final String nodeName = node.getName(); String nodeLabel = "Node " + node.getIndex(); if (!nodeName.isEmpty()) nodeLabel += " (" + nodeName + ")"; originNodeSelector.addItem(StringLabeller.of(node.getId(), nodeLabel)); destinationNodeSelector.addItem(StringLabeller.of(node.getId(), nodeLabel)); }//from w w w .j av a2s. c o m ItemListener nodeListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { long originNodeId = (long) ((StringLabeller) originNodeSelector.getSelectedItem()).getObject(); long destinationNodeId = (long) ((StringLabeller) destinationNodeSelector.getSelectedItem()) .getObject(); callback.putTransientColorInElementTopologyCanvas( Arrays.asList(netPlan.getNodeFromId(originNodeId)), Color.GREEN); callback.putTransientColorInElementTopologyCanvas( Arrays.asList(netPlan.getNodeFromId(destinationNodeId)), Color.CYAN); } }; originNodeSelector.addItemListener(nodeListener); destinationNodeSelector.addItemListener(nodeListener); originNodeSelector.setSelectedIndex(0); destinationNodeSelector.setSelectedIndex(1); JPanel pane = new JPanel(); pane.add(networkElementType == NetworkElementType.LINK ? new JLabel("Origin node: ") : new JLabel("Ingress node: ")); pane.add(originNodeSelector); pane.add(Box.createHorizontalStrut(15)); pane.add(networkElementType == NetworkElementType.LINK ? new JLabel("Destination node: ") : new JLabel("Egress node: ")); pane.add(destinationNodeSelector); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please enter end nodes for the new " + networkElementType, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long originNodeId = (long) ((StringLabeller) originNodeSelector.getSelectedItem()).getObject(); long destinationNodeId = (long) ((StringLabeller) destinationNodeSelector.getSelectedItem()) .getObject(); Node originNode = netPlan.getNodeFromId(originNodeId); Node destinationNode = netPlan.getNodeFromId(destinationNodeId); if (netPlan.getNodeFromId(originNodeId) == null) throw new Net2PlanException("Node of id: " + originNodeId + " does not exist"); if (netPlan.getNodeFromId(destinationNodeId) == null) throw new Net2PlanException("Node of id: " + destinationNodeId + " does not exist"); if (networkElementType == NetworkElementType.LINK) { final Link e = netPlan.addLink(originNode, destinationNode, 0, 0, 200000, null); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getVisualizationState().pickLink(e); callback.updateVisualizationAfterPick(); callback.getUndoRedoNavigationManager().addNetPlanChange(); } else { final Demand d = netPlan.addDemand(originNode, destinationNode, 0, null); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.DEMAND)); callback.getVisualizationState().pickDemand(d); callback.updateVisualizationAfterPick(); callback.getUndoRedoNavigationManager().addNetPlanChange(); } break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error adding " + networkElementType); } } }
From source file:mergedoc.ui.PreferencePanel.java
/** * ??????// w w w. ja va 2s . c o m * @return ?? * @throws MergeDocException ???????? */ private JComponent createUpperPanel() throws MergeDocException { // JLabel docLabel = docField.getLabel(); JLabel srcLabel = srcField.getLabel(); JLabel outLabel = outField.getLabel(); docLabel.setText("API "); srcLabel.setText(""); outLabel.setText(""); JLabel[] labels = { docLabel, srcLabel, outLabel }; ComponentFactory.ensureMaxFontWidth(labels); // JComboBox docCombo = docField.getComboBox(); JComboBox srcCombo = srcField.getComboBox(); JComboBox outCombo = outField.getComboBox(); docCombo.addItem(FileChooserField.ENCODING_AUTO); srcCombo.addItem(FileChooserField.ENCODING_AUTO); docCombo.setSelectedItem("UTF-8"); srcCombo.setSelectedItem(FileChooserField.ENCODING_DEFAULT); outCombo.setSelectedItem(FileChooserField.ENCODING_DEFAULT); JComboBox[] combos = { docCombo, srcCombo, outCombo }; ComponentFactory.ensureMaxFontWidth(combos); // ?? docField.setSelectionMode(FileChooserField.DIRECTORIES); srcField.setSelectionMode(FileChooserField.ZIP_TGZ_FILES); outField.setSelectionMode(FileChooserField.ZIP_FILES); docField.setChooseListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resolveArchivePath(docField.getFile()); } }); // ?? JPanel panel = new TitledPanel(""); panel.add(docField); panel.add(srcField); panel.add(outField); // ?? final String OPTION_KEY = "target.directory"; String targetStr = System.getProperty(OPTION_KEY); if (targetStr != null) { File targetDir = new File(targetStr); if (!targetDir.exists() || targetDir.isFile()) { throw new MergeDocException(" " + OPTION_KEY + " ??? " + targetStr + " ?\n?????????"); } File docDir = searchDocDirectory(targetDir); if (docDir != null) { docField.setFile(docDir); } srcField.setFile(new File("")); outField.setFile(new File("")); resolveArchivePath(targetDir); } // ?? loadPersister(docField, Persister.DOC_DIR, Persister.DOC_ENC); loadPersister(srcField, Persister.IN_FILE, Persister.IN_ENC); loadPersister(outField, Persister.OUT_FILE, Persister.OUT_ENC); // ? String docPath = docField.getFile().getPath(); if (docPath.equals("")) { File home = new File(System.getProperty("java.home")); if (home.getName().equals("jre")) { home = home.getParentFile(); } File docDir = new File(home, "docs/ja/api"); if (docDir.exists()) { docField.setFile(docDir); resolveArchivePath(home); } } return panel; }
From source file:mod.steps.stepmode.threads.forms.TransitionsChooser.java
private JComboBox initializeNewComboBox(String transitionId) { Map<String, Integer> repetitions = listChoosenElement.getPossibleRepetitions(); JComboBox rComboBox = new JComboBox(); int count = repetitions.get(transitionId); rComboBox.setMaximumRowCount(count); for (int i = 1; i <= count; i++) { rComboBox.addItem(i + ""); }/*from ww w. ja v a2 s. com*/ return rComboBox; }