List of usage examples for javax.swing JComboBox JComboBox
public JComboBox()
JComboBox
with a default data model. From source file:MainClass.java
public EscapeDialog(Frame owner) { super(owner, true); getContentPane().add(new JComboBox()); }
From source file:Main.java
private JComboBox createComboBox(final Map<Integer, Student> map) { final JComboBox cbox = new JComboBox(); for (Integer id : map.keySet()) { cbox.addItem(id);//from ww w . j a va2 s .c om } cbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Integer id = (Integer) cbox.getSelectedItem(); System.out.println(map.get(id)); } }); return cbox; }
From source file:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);//from w w w . j av a 2 s . co m JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:MainClass.java
public FlavorsPanel() { JComboBox jcb = new JComboBox(); jcb.addItem("Vanilla"); jcb.addItem("Chocolate"); jcb.addItem("Strawberry"); add(jcb);/* ww w .j a v a 2 s. c o m*/ }
From source file:rhinova.gui.dataentry.link.LinkDataEditPannel.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner non-commercial license label1 = new JLabel(); label2 = new JLabel(); lblId = new JLabel(); label3 = new JLabel(); txtName = new JTextField(); label8 = new JLabel(); txtCapacity = new JTextField(); label4 = new JLabel(); txtSurvivalRate = new JTextField(); label5 = new JLabel(); comboReserve1 = new JComboBox<>(); label6 = new JLabel(); comboReserve2 = new JComboBox<>(); //======== this ======== setLayout(new GridBagLayout()); ((GridBagLayout) getLayout()).columnWidths = new int[] { 54, 0, 0 }; ((GridBagLayout) getLayout()).rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; ((GridBagLayout) getLayout()).columnWeights = new double[] { 0.0, 0.0, 1.0E-4 }; ((GridBagLayout) getLayout()).rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4 }; //---- label1 ---- label1.setText("Link Properties"); label1.setFont(new Font("Tahoma", Font.PLAIN, 16)); add(label1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 15, 0), 0, 0)); //---- label2 ---- label2.setText("id"); add(label2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 15, 15), 0, 0)); add(lblId, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 15, 0), 0, 0)); //---- label3 ---- label3.setText("name"); add(label3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 15, 15), 0, 0)); add(txtName, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 15, 0), 0, 0)); //---- label8 ---- label8.setText("capacity"); add(label8, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 15, 15), 0, 0)); add(txtCapacity, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 15, 0), 0, 0)); //---- label4 ---- label4.setText("survival rate"); add(label4, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 15, 15), 0, 0)); add(txtSurvivalRate, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 15, 0), 0, 0)); //---- label5 ---- label5.setText("reserve 1"); add(label5, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 15, 15), 0, 0)); add(comboReserve1, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 15, 0), 0, 0)); //---- label6 ---- label6.setText("reserve 2"); add(label6, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 15), 0, 0)); add(comboReserve2, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:SwingThreadTest.java
public SwingThreadFrame() { setTitle("SwingThreadTest"); final JComboBox combo = new JComboBox(); combo.insertItemAt(Integer.MAX_VALUE, 0); combo.setPrototypeDisplayValue(combo.getItemAt(0)); combo.setSelectedIndex(0);// ww w. ja v a2s . c o m JPanel panel = new JPanel(); JButton goodButton = new JButton("Good"); goodButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { new Thread(new GoodWorkerRunnable(combo)).start(); } }); panel.add(goodButton); JButton badButton = new JButton("Bad"); badButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { new Thread(new BadWorkerRunnable(combo)).start(); } }); panel.add(badButton); panel.add(combo); add(panel); pack(); }
From source file:ComboBoxTest.java
public ComboBoxFrame() { setTitle("ComboBoxTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add the sample text label label = new JLabel("The quick brown fox jumps over the lazy dog."); label.setFont(new Font("Serif", Font.PLAIN, DEFAULT_SIZE)); add(label, BorderLayout.CENTER); // make a combo box and add face names faceCombo = new JComboBox(); faceCombo.setEditable(true);//from w w w. j av a2 s . c o m faceCombo.addItem("Serif"); faceCombo.addItem("SansSerif"); faceCombo.addItem("Monospaced"); faceCombo.addItem("Dialog"); faceCombo.addItem("DialogInput"); // the combo box listener changes the label font to the selected face name faceCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { label.setFont(new Font((String) faceCombo.getSelectedItem(), Font.PLAIN, DEFAULT_SIZE)); } }); // add combo box to a panel at the frame's southern border JPanel comboPanel = new JPanel(); comboPanel.add(faceCombo); add(comboPanel, BorderLayout.SOUTH); }
From source file:ViewDB.java
public ViewDBFrame() { setTitle("ViewDB"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); tableNames = new JComboBox(); tableNames.addActionListener(new ActionListener() {/*from w w w . j av a2 s . c o m*/ public void actionPerformed(ActionEvent event) { showTable((String) tableNames.getSelectedItem()); } }); add(tableNames, BorderLayout.NORTH); try { readDatabaseProperties(); Connection conn = getConnection(); try { DatabaseMetaData meta = conn.getMetaData(); ResultSet mrs = meta.getTables(null, null, null, new String[] { "TABLE" }); while (mrs.next()) tableNames.addItem(mrs.getString(3)); } finally { conn.close(); } } catch (SQLException e) { JOptionPane.showMessageDialog(this, e); } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } JPanel buttonPanel = new JPanel(); add(buttonPanel, BorderLayout.SOUTH); previousButton = new JButton("Previous"); previousButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { showPreviousRow(); } }); buttonPanel.add(previousButton); nextButton = new JButton("Next"); nextButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { showNextRow(); } }); buttonPanel.add(nextButton); deleteButton = new JButton("Delete"); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { deleteRow(); } }); buttonPanel.add(deleteButton); saveButton = new JButton("Save"); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveChanges(); } }); buttonPanel.add(saveButton); }
From source file:Interface.Stats.java
/** * * @param f //from ww w . jav 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:com.anrisoftware.prefdialog.miscswing.validatingfields.ValidatingComboBoxEditor.java
/** * @see BasicComboBoxEditor#BasicComboBoxEditor() *//*www. ja va 2s. co m*/ public ValidatingComboBoxEditor() { this.editorType = new JComboBox<Object>().getEditor().getClass(); this.validating = (ValidatingTextField) createEditorComponent(); }