List of usage examples for javax.swing JComboBox JComboBox
public JComboBox()
JComboBox
with a default data model. From source file:EditorPaneExample17.java
public EditorPaneExample17() { super("JEditorPane Example 17"); pane = new JEditorPane(); pane.setEditable(true); // Editable 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 a va 2s . co 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.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.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"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit"); } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // 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)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:com.hexidec.ekit.component.PropertiesDialog.java
public PropertiesDialog(Window parent, String[] fields, String[] types, String[] values, String title, boolean bModal) { super(parent, title); setModal(bModal);//w w w . j a va2 s. c o m htInputFields = new Hashtable<String, JComponent>(); final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"), Translatrix.getTranslationString("DialogCancel") }; List<Object> panelContents = new ArrayList<Object>(); for (int iter = 0; iter < fields.length; iter++) { String fieldName = fields[iter]; String fieldType = types[iter]; JComponent fieldComponent; JComponent panelComponent = null; if (fieldType.equals("text") || fieldType.equals("integer")) { fieldComponent = new JTextField(3); if (values[iter] != null && values[iter].length() > 0) { ((JTextField) (fieldComponent)).setText(values[iter]); } if (fieldType.equals("integer")) { ((AbstractDocument) ((JTextField) (fieldComponent)).getDocument()) .setDocumentFilter(new DocumentFilter() { @Override public void insertString(FilterBypass fb, int offset, String text, AttributeSet attrs) throws BadLocationException { replace(fb, offset, 0, text, attrs); } @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { if (StringUtils.isNumeric(text)) { super.replace(fb, offset, length, text, attrs); } } }); } } else if (fieldType.equals("bool")) { fieldComponent = new JCheckBox(fieldName); if (values[iter] != null) { ((JCheckBox) (fieldComponent)).setSelected(values[iter] == "true"); } panelComponent = fieldComponent; } else if (fieldType.equals("combo")) { fieldComponent = new JComboBox(); if (values[iter] != null) { StringTokenizer stParse = new StringTokenizer(values[iter], ",", false); while (stParse.hasMoreTokens()) { ((JComboBox) (fieldComponent)).addItem(stParse.nextToken()); } } } else { fieldComponent = new JTextField(3); } htInputFields.put(fieldName, fieldComponent); if (panelComponent == null) { panelContents.add(fieldName); panelContents.add(fieldComponent); } else { panelContents.add(panelComponent); } } jOptionPane = new JOptionPane(panelContents.toArray(), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]); setContentPane(jOptionPane); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); jOptionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (isVisible() && (e.getSource() == jOptionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) { Object value = jOptionPane.getValue(); if (value == JOptionPane.UNINITIALIZED_VALUE) { return; } if (value.equals(buttonLabels[0])) { setVisible(false); } else { setVisible(false); } } } }); this.pack(); setLocation(SwingUtilities.getPointForCentering(this, parent)); }
From source file:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java
public AddPanel(JDialog parentDialog, IEngine engine) { Arguments.assertNotNull("parentDialog", parentDialog); Arguments.assertNotNull("engine", engine); this.parentDialog = parentDialog; this.engine = engine; fileChooser = new FileChooser(); encodingComboBox = new JComboBox(); encodingAutoComboBox = new JComboBox(new String[] { resources.text("encoding_auto") }); encodingAutoComboBox.setEnabled(false); encodingCardPanel = new CardPanel(); encodingCardPanel.add(encodingComboBox); encodingCardPanel.add(encodingAutoComboBox); readerList = Components//from w w w .jav a 2 s. com .list(new StaticListModel<IDictionaryReader>(new ReaderLabelBuilder(), engine.getReaders())); readerList.setSelectedIndex(0); editorPane = Components.editorPane(); editorPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { Browser.openUrl(e.getURL().toExternalForm()); } } }); continueButton = Buttons.continue1(); continueButton.setDefaultCapable(true); closeButton = Buttons.cancel(); JPanel buttonPanel = new JPanel(new GridLayout(1, 2, GAP5, GAP5)); buttonPanel.add(continueButton); buttonPanel.add(closeButton); JPanel listReaderPanel = new JPanel(new BorderLayout()); listReaderPanel.add(resources.label("reader"), BorderLayout.NORTH); listReaderPanel.add(new JScrollPane(readerList), BorderLayout.CENTER); readerList.setPreferredSize(new Dimension(50, 50)); listReaderPanel.setPreferredSize(new Dimension(100, 100)); JPanel descriptionReaderPanel = new JPanel(new BorderLayout()); descriptionReaderPanel.add(resources.label("readerDescription"), BorderLayout.NORTH); descriptionReaderPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listReaderPanel, descriptionReaderPanel); splitPane.setContinuousLayout(true); splitPane.setDividerLocation(130); gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED, GAP5, TableLayout.FILL }, { TableLayout.FILL, // 0: reader panel GAP5, TableLayout.PREFERRED, // 2: file GAP5, TableLayout.PREFERRED, // 4: encoding GAP5 * 2, TableLayout.PREFERRED // 6: button panel } })); gui.add(splitPane, "0, 0, 2, 0"); gui.add(resources.label("file"), "0, 2"); gui.add(fileChooser.getGui(), "2, 2"); gui.add(resources.label("encoding"), "0, 4"); gui.add(encodingCardPanel.getGui(), "2, 4"); gui.add(buttonPanel, "0, 6, 2, 6, right, center"); Gaps.applyBorder7(gui); ActionBinder.bind(this); if (encodingComboBox.getModel().getSize() > 0) { encodingComboBox.setSelectedIndex(0); } // filters for (IDictionaryReader reader : engine.getReaders()) { fileChooser.getChooser().addChoosableFileFilter(reader.getFileFilter()); } onReaderSelected(); onFileFieldEdited(); }
From source file:org.jax.bham.test.HaplotypeAssociationTestGraphPanel.java
/** * Constructor/*from w ww . java2 s . c o m*/ * @param testToPlot * the test that we're plotting */ public HaplotypeAssociationTestGraphPanel(HaplotypeAssociationTest testToPlot) { super(new BorderLayout()); this.testToPlot = testToPlot; this.chromosomeComboBox = new JComboBox(); this.initialize(); }
From source file:org.jax.bham.test.MultiHaplotypeBlockTestGraphPanel.java
/** * Constructor/*w w w .j a v a2 s . c o m*/ * @param testToPlot * the test for this panel to plot */ public MultiHaplotypeBlockTestGraphPanel(MultiHaplotypeBlockTest testToPlot) { super(new BorderLayout()); this.testToPlot = testToPlot; this.chromosomeComboBox = new JComboBox(); this.initialize(); }
From source file:org.jax.bham.test.PhylogenyAssociationTestGraphPanel.java
/** * Constructor//from w w w . j a va 2s . c o m * @param testToPlot * the test that we're plotting */ public PhylogenyAssociationTestGraphPanel(PhylogenyAssociationTest testToPlot) { super(new BorderLayout()); this.testToPlot = testToPlot; this.chromosomeComboBox = new JComboBox(); this.initialize(); }
From source file:components.TableRenderDemo.java
public void setUpSportColumn(JTable table, TableColumn sportColumn) { //Set up the editor for the sport cells. JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); //Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); sportColumn.setCellRenderer(renderer); }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.ADAP3DecompositionV1_5SetupDialog.java
@Override protected void addDialogComponents() { super.addDialogComponents(); comboPeakList = new JComboBox<>(); comboClustersModel = new DefaultComboBoxModel<>(); comboClusters = new JComboBox<>(comboClustersModel); retTimeMZPlot = new SimpleScatterPlot("Retention time", "m/z"); retTimeIntensityPlot = new EICPlot(); PeakList[] peakLists = MZmineCore.getDesktop().getSelectedPeakLists(); // ----------------------------- // Panel with preview parameters // ----------------------------- preview = new JCheckBox("Show preview"); preview.addActionListener(this); preview.setHorizontalAlignment(SwingConstants.CENTER); if (peakLists == null || peakLists.length == 0) preview.setEnabled(false);/*w ww . j a va 2 s . c o m*/ else preview.setEnabled(true); final JPanel previewPanel = new JPanel(new BorderLayout()); previewPanel.add(new JSeparator(), BorderLayout.NORTH); previewPanel.add(preview, BorderLayout.CENTER); previewPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH); comboPeakList.setFont(COMBO_FONT); for (final PeakList peakList : peakLists) if (peakList.getNumberOfRawDataFiles() == 1) comboPeakList.addItem(peakList); comboPeakList.addActionListener(this); comboClusters.setFont(COMBO_FONT); comboClusters.addActionListener(this); pnlLabelsFields = GUIUtils.makeTablePanel(2, 2, new JComponent[] { new JLabel("Peak list"), comboPeakList, new JLabel("Cluster list"), comboClusters }); pnlVisible = new JPanel(new BorderLayout()); pnlVisible.add(previewPanel, BorderLayout.NORTH); // -------------------------------------------------------------------- // ----- Tabbed panel with plots -------------------------------------- // -------------------------------------------------------------------- // pnlTabs = new JTabbedPane(); pnlTabs = new JPanel(); pnlTabs.setLayout(new BoxLayout(pnlTabs, BoxLayout.Y_AXIS)); retTimeMZPlot.setMinimumSize(MIN_DIMENSIONS); JPanel pnlPlotRetTimeClusters = new JPanel(new BorderLayout()); pnlPlotRetTimeClusters.setBackground(Color.white); pnlPlotRetTimeClusters.add(retTimeMZPlot, BorderLayout.CENTER); GUIUtils.addMarginAndBorder(pnlPlotRetTimeClusters, 10); pnlTabs.add(pnlPlotRetTimeClusters); retTimeIntensityPlot.setMinimumSize(MIN_DIMENSIONS); JPanel pnlPlotShapeClusters = new JPanel(new BorderLayout()); pnlPlotShapeClusters.setBackground(Color.white); pnlPlotShapeClusters.add(retTimeIntensityPlot, BorderLayout.CENTER); GUIUtils.addMarginAndBorder(pnlPlotShapeClusters, 10); pnlTabs.add(pnlPlotShapeClusters); super.mainPanel.add(pnlVisible, 0, super.getNumberOfParameters() + 3, 2, 1, 0, 0, GridBagConstraints.HORIZONTAL); }
From source file:gtu._work.ui.LogAppendStartEndUI.java
private void initGUI() { try {// ww w .j a v a 2s . co m BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); GridLayout jPanel1Layout = new GridLayout(10, 1); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("java\u6a94"); } { javaSrcFileText = new JTextField(); jPanel1.add(javaSrcFileText); JCommonUtil.jTextFieldSetFilePathMouseEvent(javaSrcFileText, false); } { jLabel2 = new JLabel(); jPanel1.add(jLabel2); jLabel2.setText("method\u958b\u59cb"); } { methodStartText = new JTextField(); methodStartText.setText("\"#. ${method} .s\""); jPanel1.add(methodStartText); } { jLabel3 = new JLabel(); jPanel1.add(jLabel3); jLabel3.setText("method\u7d50\u675f"); } { methodEndText = new JTextField(); methodEndText.setText("\"#. ${method} .e\""); jPanel1.add(methodEndText); } { jLabel4 = new JLabel(); jPanel1.add(jLabel4); jLabel4.setText( "\u7528\u684c\u9762\u8a2d\u5b9a\u6a94\u6c7a\u5b9adebug\u958b\u8d77\u6216\u95dc\u9589"); } { ComboBoxModel onOffDebugSwitchComboBoxModel = new DefaultComboBoxModel( new String[] { "false", "true" }); onOffDebugSwitchComboBox = new JComboBox(); jPanel1.add(onOffDebugSwitchComboBox); onOffDebugSwitchComboBox.setModel(onOffDebugSwitchComboBoxModel); } { executeBtn = new JButton(); jPanel1.add(executeBtn); executeBtn.setText("\u57f7\u884c"); executeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { executeBtnActionPerformed(evt); } }); } } } pack(); this.setSize(587, 404); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }
From source file:com.microsoft.alm.plugin.idea.ui.branch.CreateBranchForm.java
/** * Method generated by IntelliJ IDEA GUI Designer * >>> IMPORTANT!! <<< * DO NOT edit this method OR call it in your code! * * @noinspection ALL// w w w . j a va 2 s . c o m */ private void $$$setupUI$$$() { contentPanel = new JPanel(); contentPanel.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1)); nameLabel = new JLabel(); this.$$$loadLabelText$$$(nameLabel, ResourceBundle.getBundle("com/microsoft/alm/plugin/idea/ui/tfplugin") .getString("CreateBranchDialog.NameLabel")); contentPanel.add(nameLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); remoteBranchComboBox = new JComboBox(); contentPanel.add(remoteBranchComboBox, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); nameTextField = new JTextField(); contentPanel.add(nameTextField, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false)); basedOn = new JLabel(); this.$$$loadLabelText$$$(basedOn, ResourceBundle.getBundle("com/microsoft/alm/plugin/idea/ui/tfplugin") .getString("CreateBranchDialog.BasedOn")); contentPanel.add(basedOn, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); }