List of usage examples for javax.swing JComboBox JComboBox
public JComboBox()
JComboBox
with a default data model. From source file:QueryDB.java
public QueryDBFrame() { setTitle("QueryDB"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); setLayout(new GridBagLayout()); authors = new JComboBox(); authors.setEditable(false);/*from ww w.j a va 2s . co m*/ authors.addItem("Any"); publishers = new JComboBox(); publishers.setEditable(false); publishers.addItem("Any"); result = new JTextArea(4, 50); result.setEditable(false); priceChange = new JTextField(8); priceChange.setText("-5.00"); try { conn = getConnection(); Statement stat = conn.createStatement(); String query = "SELECT Name FROM Authors"; ResultSet rs = stat.executeQuery(query); while (rs.next()) authors.addItem(rs.getString(1)); rs.close(); query = "SELECT Name FROM Publishers"; rs = stat.executeQuery(query); while (rs.next()) publishers.addItem(rs.getString(1)); rs.close(); stat.close(); } catch (SQLException e) { for (Throwable t : e) result.append(t.getMessage()); } catch (IOException e) { result.setText("" + e); } // we use the GBC convenience class of Core Java Volume 1 Chapter 9 add(authors, new GBC(0, 0, 2, 1)); add(publishers, new GBC(2, 0, 2, 1)); JButton queryButton = new JButton("Query"); queryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { executeQuery(); } }); add(queryButton, new GBC(0, 1, 1, 1).setInsets(3)); JButton changeButton = new JButton("Change prices"); changeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { changePrices(); } }); add(changeButton, new GBC(2, 1, 1, 1).setInsets(3)); add(priceChange, new GBC(3, 1, 1, 1).setFill(GBC.HORIZONTAL)); add(new JScrollPane(result), new GBC(0, 2, 4, 1).setFill(GBC.BOTH).setWeight(100, 100)); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { try { if (conn != null) conn.close(); } catch (SQLException e) { for (Throwable t : e) t.printStackTrace(); } } }); }
From source file:DatabaseBrowser.java
protected JPanel getSelectionPanel() { JPanel panel = new JPanel(); panel.add(new JLabel("Catalog")); panel.add(new JLabel("Schema")); panel.add(new JLabel("Table")); catalogBox = new JComboBox(); populateCatalogBox();//from ww w . j a v a2s . c o m panel.add(catalogBox); schemaBox = new JComboBox(); populateSchemaBox(); panel.add(schemaBox); tableBox = new JComboBox(); populateTableBox(); panel.add(tableBox); catalogBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { String newCatalog = (String) (catalogBox.getSelectedItem()); try { connection.setCatalog(newCatalog); } catch (Exception e) { } populateSchemaBox(); populateTableBox(); refreshTable(); } }); schemaBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { populateTableBox(); refreshTable(); } }); tableBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { refreshTable(); } }); return panel; }
From source file:EditorPaneExample10A.java
public EditorPaneExample10A() { super("JEditorPane Example 10 - using getIterator"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;//w w w. j av a 2s . c o m c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); try { // Check if the new page and the old // page are the same. URL url; if (selection instanceof URL) { url = (URL) selection; } else { url = new URL((String) selection); } URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(url)) { return; } // Try to display the page urlCombo.setEnabled(false); // Disable input urlCombo.paintImmediately(0, 0, urlCombo.getSize().width, urlCombo.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); timeLabel.setText(""); timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height); startTime = System.currentTimeMillis(); // Choose the loading method if (onlineLoad.isSelected()) { // Usual load via setPage pane.setPage(url); loadedType.setText(pane.getContentType()); } else { pane.setContentType("text/html"); loadedType.setText(pane.getContentType()); if (loader == null) { loader = new HTMLDocumentLoader(); } HTMLDocument doc = loader.loadDocument(url); loadComplete(); pane.setDocument(doc); displayLoadTime(); populateCombo(findLinks(doc, null)); enableInput(); } } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", selection.toString() }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); enableInput(); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); enableInput(); } } }); }
From source file:com.limegroup.gnutella.gui.init.LanguagePanel.java
/** * Constructs a LanguagePanel that will notify the given listener when the * language changes.// w w w. j a v a 2s . co m */ public LanguagePanel(ActionListener actionListener) { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.actionListener = actionListener; this.languageLabel = new JLabel(); languageOptions = new JComboBox<Object>(); Font font = new Font("Dialog", Font.PLAIN, 11); languageOptions.setFont(font); Locale[] locales = LanguageUtils.getLocales(font); languageOptions.setModel(new DefaultComboBoxModel<Object>(locales)); languageOptions.setRenderer(LanguageFlagFactory.getListRenderer()); Locale locale = guessLocale(locales); languageOptions.setSelectedItem(locale); applySettings(false); // It is important that the listener is added after the selected item // is set. Otherwise the listener will call methods that are not ready // to be called at this point. languageOptions.addItemListener(new StateListener()); add(languageLabel); add(Box.createHorizontalStrut(5)); add(languageOptions); }
From source file:ShapeTest.java
public ShapeTestFrame() { setTitle("ShapeTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final ShapeComponent comp = new ShapeComponent(); add(comp, BorderLayout.CENTER); final JComboBox comboBox = new JComboBox(); comboBox.addItem(new LineMaker()); comboBox.addItem(new RectangleMaker()); comboBox.addItem(new RoundRectangleMaker()); comboBox.addItem(new EllipseMaker()); comboBox.addItem(new ArcMaker()); comboBox.addItem(new PolygonMaker()); comboBox.addItem(new QuadCurveMaker()); comboBox.addItem(new CubicCurveMaker()); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { ShapeMaker shapeMaker = (ShapeMaker) comboBox.getSelectedItem(); comp.setShapeMaker(shapeMaker); }// w w w .j ava2 s. co m }); add(comboBox, BorderLayout.NORTH); comp.setShapeMaker((ShapeMaker) comboBox.getItemAt(0)); }
From source file:fll.scheduler.ChooseChallengeDescriptor.java
private void initComponents() { getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1;// ww w. ja v a 2 s . c o m gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; final JTextArea instructions = new JTextArea( "Choose a challenge description from the drop down list OR choose a file containing your custom challenge description.", 3, 40); instructions.setEditable(false); instructions.setWrapStyleWord(true); instructions.setLineWrap(true); getContentPane().add(instructions, gbc); gbc = new GridBagConstraints(); mCombo = new JComboBox<DescriptionInfo>(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(mCombo, gbc); mCombo.setRenderer(new DescriptionInfoRenderer()); mCombo.setEditable(false); final List<DescriptionInfo> descriptions = DescriptionInfo.getAllKnownChallengeDescriptionInfo(); for (final DescriptionInfo info : descriptions) { mCombo.addItem(info); } mFileField = new JLabel(); gbc = new GridBagConstraints(); gbc.weightx = 1; getContentPane().add(mFileField, gbc); final JButton chooseButton = new JButton("Choose File"); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(chooseButton, gbc); chooseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mFileField.setText(null); final JFileChooser fileChooser = new JFileChooser(); final FileFilter filter = new BasicFileFilter("FLL Description (xml)", new String[] { "xml" }); fileChooser.setFileFilter(filter); final int returnVal = fileChooser.showOpenDialog(ChooseChallengeDescriptor.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File selectedFile = fileChooser.getSelectedFile(); mFileField.setText(selectedFile.getAbsolutePath()); } } }); final Box buttonPanel = new Box(BoxLayout.X_AXIS); gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; getContentPane().add(buttonPanel, gbc); buttonPanel.add(Box.createHorizontalGlue()); final JButton ok = new JButton("Ok"); buttonPanel.add(ok); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { // use the selected description if nothing is entered in the file box final DescriptionInfo descriptionInfo = mCombo.getItemAt(mCombo.getSelectedIndex()); if (null != descriptionInfo) { mSelected = descriptionInfo.getURL(); } final String text = mFileField.getText(); if (!StringUtils.isEmpty(text)) { final File file = new File(text); if (file.exists()) { try { mSelected = file.toURI().toURL(); } catch (final MalformedURLException e) { throw new FLLInternalException("Can't turn file into URL?", e); } } } setVisible(false); } }); final JButton cancel = new JButton("Cancel"); buttonPanel.add(cancel); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { mSelected = null; setVisible(false); } }); pack(); }
From source file:TableCellRenderTest.java
public TableCellRenderFrame() { setTitle("TableCellRenderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new PlanetTableModel(); JTable table = new JTable(model); table.setRowSelectionAllowed(false); // set up renderers and editors table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); table.setDefaultEditor(Color.class, new ColorTableCellEditor()); JComboBox moonCombo = new JComboBox(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i);/*ww w . j a v a 2s .c o m*/ TableColumnModel columnModel = table.getColumnModel(); TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN); moonColumn.setCellEditor(new DefaultCellEditor(moonCombo)); moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class)); moonColumn.setHeaderValue(new ImageIcon("Moons.gif")); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
From source file:eu.dety.burp.joseph.utilities.Converter.java
/** * Get RSA PublicKey by PublicKey HashMap input. Create a dialog popup with a combobox to choose the correct JWK to use. * // w ww. jav a 2 s .c o m * @param publicKeys * HashMap containing a PublicKey and related describing string * @throws AttackPreparationFailedException * @return Selected {@link PublicKey} */ @SuppressWarnings("unchecked") public static PublicKey getRsaPublicKeyByJwkSelectionPanel(HashMap<String, PublicKey> publicKeys) throws AttackPreparationFailedException { // TODO: Move to other class? JPanel selectionPanel = new JPanel(); selectionPanel.setLayout(new java.awt.GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridy = 0; selectionPanel.add(new JLabel("Multiple JWKs found. Please choose one:"), constraints); JComboBox jwkSetKeySelection = new JComboBox<>(); DefaultComboBoxModel<String> jwkSetKeySelectionModel = new DefaultComboBoxModel<>(); for (Map.Entry<String, PublicKey> publicKey : publicKeys.entrySet()) { jwkSetKeySelectionModel.addElement(publicKey.getKey()); } jwkSetKeySelection.setModel(jwkSetKeySelectionModel); constraints.gridy = 1; selectionPanel.add(jwkSetKeySelection, constraints); int resultButton = JOptionPane.showConfirmDialog(null, selectionPanel, "Select JWK", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (resultButton == JOptionPane.CANCEL_OPTION) { throw new AttackPreparationFailedException("No JWK from JWK Set selected!"); } loggerInstance.log(Converter.class, "Key selected: " + jwkSetKeySelection.getSelectedIndex(), Logger.LogLevel.DEBUG); return publicKeys.get(jwkSetKeySelection.getSelectedItem()); }
From source file:net.brtly.monkeyboard.plugin.ConsolePanel.java
public ConsolePanel(PluginDelegate service) { super(service); setLayout(new MigLayout("inset 5", "[grow][:100:100][24:n:24][24:n:24]", "[::24][grow]")); JComboBox comboBox = new JComboBox(); comboBox.setToolTipText("Log Level"); comboBox.setMaximumRowCount(6);// w ww. j a v a2s.c om comboBox.setModel( new DefaultComboBoxModel(new String[] { "Fatal", "Error", "Warn", "Info", "Debug", "Trace" })); comboBox.setSelectedIndex(5); add(comboBox, "cell 1 0,growx"); JButton btnC = new JButton(""); btnC.setToolTipText("Clear Buffer"); btnC.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/clear-document.png"))); btnC.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { logPangrams(); } }); add(btnC, "cell 2 0,wmax 24,hmax 26"); tglbtnV = new JToggleButton(""); tglbtnV.setToolTipText("Auto Scroll"); tglbtnV.setIcon(new ImageIcon(ConsolePanel.class.getResource("/img/auto-scroll.png"))); tglbtnV.setSelected(true); tglbtnV.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.SELECTED) { _table.setAutoScroll(true); } else if (ev.getStateChange() == ItemEvent.DESELECTED) { _table.setAutoScroll(false); } } }); add(tglbtnV, "cell 3 0,wmax 24,hmax 26"); scrollPane = new JScrollPane(); scrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { // TODO figure out what to do with this event? } }); add(scrollPane, "cell 0 1 4 1,grow"); _table = new JLogTable("Time", "Source", "Message"); _table.getColumnModel().getColumn(0).setMinWidth(50); _table.getColumnModel().getColumn(0).setPreferredWidth(50); _table.getColumnModel().getColumn(0).setMaxWidth(100); _table.getColumnModel().getColumn(1).setMinWidth(50); _table.getColumnModel().getColumn(1).setPreferredWidth(50); _table.getColumnModel().getColumn(1).setMaxWidth(100); _table.getColumnModel().getColumn(2).setMinWidth(50); _table.getColumnModel().getColumn(2).setWidth(255); _table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); scrollPane.setViewportView(_table); _appender = new JLogTableAppender(); _appender.setThreshold(Level.ALL); Logger.getRootLogger().addAppender(_appender); }
From source file:com.qspin.qtaste.ui.config.EngineTestConfigPanel.java
public void genUI() { scriptPanel = new JPanel(); reportingPanel = new JPanel(); JLabel reportingFormatLabel = new JLabel(); reportingFormatLabelComboBox = new JComboBox(); JLabel reportingDirLabel = new javax.swing.JLabel(); reportingDirLabelTextField = new javax.swing.JTextField(); reportingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Reporting")); reportingFormatLabel.setText("Format"); reportingFormatLabelComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "HTML", "XML" })); reportingDirLabel.setText("Directory:"); reportingDirLabelTextField.setText("jTextField3"); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(reportingPanel); reportingPanel.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(reportingFormatLabel) .addGap(18, 18, 18).addComponent(reportingFormatLabelComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(reportingDirLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(reportingDirLabelTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(78, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(reportingFormatLabel).addComponent(reportingFormatLabelComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18)/*from ww w. j a v a 2 s. c om*/ .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(reportingDirLabel).addComponent(reportingDirLabelTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(89, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(reportingPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(scriptPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(scriptPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(reportingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); }