List of usage examples for javax.swing JComboBox JComboBox
public JComboBox()
JComboBox
with a default data model. From source file:org.jfree.chart.demo.DrawStringDemo.java
private JPanel createTab1Content() { JPanel jpanel = new JPanel(new BorderLayout()); combo1 = new JComboBox(); combo1.setActionCommand("combo1.changed"); populateTextAnchorCombo(combo1);//from w w w . ja v a 2 s . c o m combo1.addActionListener(this); JPanel jpanel1 = new JPanel(); jpanel1.add(combo1); JButton jbutton = new JButton("Select Font..."); jbutton.setActionCommand("fontButton.clicked"); jbutton.addActionListener(this); jpanel1.add(jbutton); jpanel.add(jpanel1, "North"); drawStringPanel1 = new DrawStringPanel("0123456789", false); jpanel.add(drawStringPanel1); return jpanel; }
From source file:lu.lippmann.cdb.datasetview.tabs.WeightedMapOfDecisionTreesTabView.java
/** * Constructor.// w w w .ja v a 2 s .co m */ public WeightedMapOfDecisionTreesTabView(final EventPublisher eventPublisher, final CommandDispatcher commandDispatcher, final ApplicationContext applicationContext) { super(); this.applicationContext = applicationContext; this.commandDispatcher = commandDispatcher; this.eventPublisher = eventPublisher; final double defaultValueConfidenceFactor = DecisionTreeHelper.HIGH_CONFIDENCE_FACTOR; this.dtFactory = new J48DecisionTreeFactory(defaultValueConfidenceFactor, false); this.panel = new JXPanel(); this.panel.setLayout(new BorderLayout()); this.slider = new JSlider(); this.slider.setBorder(new TitledBorder("Confidence factor")); this.slider.setOpaque(false); this.slider.setMaximum((int) (defaultValueConfidenceFactor * 100)); this.slider.setValue((int) (defaultValueConfidenceFactor * 100)); this.slider.setMinimum(1); this.slider.setMinorTickSpacing(1); this.slider.setMajorTickSpacing(10); this.slider.setPaintTicks(true); this.slider.setPaintLabels(true); this.panel.add(this.slider, BorderLayout.SOUTH); this.attrSelectionCombo = new JComboBox(); this.attrSelectionCombo.setBorder(new TitledBorder("Attribute used to split")); final JXPanel cmdPanel = new JXPanel(); cmdPanel.setLayout(new BorderLayout()); cmdPanel.add(this.attrSelectionCombo, BorderLayout.CENTER); this.withWeightCheckBox = new JCheckBox("Weighted"); this.withWeightCheckBox.setBorder(new TitledBorder("With weight")); cmdPanel.add(this.withWeightCheckBox, BorderLayout.EAST); this.panel.add(cmdPanel, BorderLayout.NORTH); }
From source file:com.intuit.tank.tools.debugger.FindReplaceDialog.java
/** * Constructs a new find dialog according to the specified type of dialog requested. The dialog can be either a FIND * dialog, either a REPLACE dialog. In both cases, components displayed remain the sames, but the ones specific to * replace feature are grayed out.//from w w w.jav a2 s .com * * @param parent * The window holder * @param type * The type of the dialog: FindReplace.FIND or FindReplace.REPLACE * @param modal * Displays dialog as a modal window if true */ public FindReplaceDialog(AgentDebuggerFrame parent, DialogType type) { super(parent, type == DialogType.REPLACE ? "Replace" : "Find", true); this.parent = parent; cbSearch = new JComboBox(); cbSearch.setEditable(true); cbReplace = new JComboBox(); cbReplace.setEditable(true); KeyHandler handler = new KeyHandler(); tfSearchEditor = (JTextField) cbSearch.getEditor().getEditorComponent(); tfSearchEditor.addKeyListener(handler); tfReplaceEditor = (JTextField) cbReplace.getEditor().getEditorComponent(); tfReplaceEditor.addKeyListener(handler); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); getContentPane().setLayout(gridbag); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); int gridX = 0; int gridY = 0; JLabel findLabel = new JLabel("Find"); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.WEST; gridbag.setConstraints(findLabel, constraints); getContentPane().add(findLabel); gridX++; buildConstraints(constraints, gridX, gridY, 1, 1, 100, 0); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(cbSearch, constraints); getContentPane().add(cbSearch); gridX++; btnFind = new JButton("Find"); btnFind.setToolTipText("Find text in scripts"); btnFind.setMnemonic('F'); btnFind.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnFind, constraints); getContentPane().add(btnFind); getRootPane().setDefaultButton(btnFind); gridX++; btnCancel = new JButton("Cancel"); btnCancel.setMnemonic('C'); btnCancel.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnCancel, constraints); getContentPane().add(btnCancel); gridY++; gridX = 0; if (type == DialogType.REPLACE) { JLabel replaceLabel = new JLabel("Replace"); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.WEST; gridbag.setConstraints(replaceLabel, constraints); getContentPane().add(replaceLabel); gridX++; buildConstraints(constraints, gridX, gridY, 1, 1, 100, 0); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(cbReplace, constraints); getContentPane().add(cbReplace); gridX++; btnReplace = new JButton("Replace"); btnReplace.setToolTipText("REplace in script"); btnReplace.setMnemonic('R'); btnReplace.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnReplace, constraints); getContentPane().add(btnReplace); gridX++; btnReplaceAll = new JButton("Replace All"); btnReplaceAll.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnReplaceAll, constraints); getContentPane().add(btnReplaceAll); btnReplace.addKeyListener(handler); btnReplaceAll.addKeyListener(handler); gridY++; gridX = 0; } TitledBorder border = new TitledBorder("Options"); JPanel panel = new JPanel(new GridLayout(1, 4)); panel.setBorder(border); checkboxWrap = new JCheckBox("Wrap Search"); panel.add(checkboxWrap); checkboxMatchCase = new JCheckBox("Case sensitive"); panel.add(checkboxMatchCase); checkboxRegexp = new JCheckBox("Regular expressions"); panel.add(checkboxRegexp); buildConstraints(constraints, gridX, gridY, 4, 1, 100, 100); constraints.anchor = GridBagConstraints.WEST; gridbag.setConstraints(panel, constraints); getContentPane().add(panel); FontMetrics fm = getFontMetrics(getFont()); cbSearch.setPreferredSize(new Dimension(18 * fm.charWidth('m'), (int) cbSearch.getPreferredSize().height)); cbReplace .setPreferredSize(new Dimension(18 * fm.charWidth('m'), (int) cbReplace.getPreferredSize().height)); pack(); // setResizable(false); WindowUtil.centerOnParent(this); // patch by MJB 8/1/2002 btnFind.addKeyListener(handler); btnCancel.addKeyListener(handler); checkboxMatchCase.addKeyListener(handler); checkboxRegexp.addKeyListener(handler); }
From source file:org.encog.workbench.tabs.rbf.RadialBasisFunctionsTab.java
public RadialBasisFunctionsTab() { super(null);//from w ww .j a va 2s . c o m this.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(); add(buttonPanel, BorderLayout.SOUTH); this.buttonClose = new JButton("Close"); buttonPanel.add(this.buttonClose); this.buttonClose.addActionListener(this); //this.weightInfo = new WeightInfo(this); //this.add(this.weightInfo,BorderLayout.NORTH); // double[] center = { 0.0 }; this.rbf = new GaussianFunction(1.0, center, 1.0); XYDataset dataset = this.createDataset(); JFreeChart chart = this.createChart(dataset); this.chartPanel = new EncogChartPanel(chart); this.add(chartPanel, BorderLayout.CENTER); this.typeCombo = new JComboBox(); this.add(this.typeCombo, BorderLayout.NORTH); this.typeCombo.addItem(GaussianFunction.class.getSimpleName()); this.typeCombo.addItem(MultiquadricFunction.class.getSimpleName()); this.typeCombo.addItem(InverseMultiquadricFunction.class.getSimpleName()); this.typeCombo.addItem(MexicanHatFunction.class.getSimpleName()); this.typeCombo.addActionListener(this); }
From source file:gtu.xml.work.CacDBUI4Janna.java
private void initGUI() { try {/*from w ww .java 2 s. 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, 2, 5, 5); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("\u8cc7\u6599\u8868\u540d\u7a31"); } { ComboBoxModel tableNameComboModel = new DefaultComboBoxModel( new String[] { "cac_fcase", "cac_ecase", "cac_fcase_count" }); tableNameCombo = new JComboBox(); jPanel1.add(tableNameCombo); tableNameCombo.setModel(tableNameComboModel); } { jLabel2 = new JLabel(); jPanel1.add(jLabel2); jLabel2.setText("xml\u6a94\u6848\u4f86\u6e90"); } { srcFileText = new JTextField(); JCommonUtil.jTextFieldSetFilePathMouseEvent(srcFileText, false); jPanel1.add(srcFileText); } { jLabel3 = new JLabel(); jPanel1.add(jLabel3); jLabel3.setText("\u7522\u751fsql\u6a94\u540d"); } { destFileNameText = new JTextField(); jPanel1.add(destFileNameText); } { jLabel4 = new JLabel(); jPanel1.add(jLabel4); jLabel4.setText("dmv\u6b04\u4f4d\u503c"); } { dmvText = new JTextField(); jPanel1.add(dmvText); } { executeBtn = new JButton(); jPanel1.add(executeBtn); executeBtn.setText("\u57f7\u884c"); executeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { executeBtnActionPerformed(evt); } }); } } } pack(); this.setSize(541, 361); } catch (Exception e) { // add your error handling code here e.printStackTrace(); } }
From source file:NormSample.java
public void init() { // preparing values for the normalization forms ComboBox formValues.put("NFC", Normalizer.Form.NFC); formValues.put("NFD", Normalizer.Form.NFD); formValues.put("NFKC", Normalizer.Form.NFKC); formValues.put("NFKD", Normalizer.Form.NFKD); formComboBox = new JComboBox(); for (Iterator it = formValues.keySet().iterator(); it.hasNext();) { formComboBox.addItem((String) it.next()); }/*from w w w . j av a2s . c o m*/ // preparing samples for normalization // text with the acute accent symbol templateValues.put("acute accent", "touch" + "\u00e9"); // text with ligature templateValues.put("ligature", "a" + "\ufb03" + "ance"); // text with the cedilla templateValues.put("cedilla", "fa" + "\u00e7" + "ade"); // text with half-width katakana templateValues.put("half-width katakana", "\uff81\uff6e\uff7a\uff9a\uff70\uff84"); normalizationTemplate = new JComboBox(); for (Iterator it = templateValues.keySet().iterator(); it.hasNext();) { normalizationTemplate.addItem((String) it.next()); } // defining a component to output normalization results paintingComponent = new JComponent() { static final long serialVersionUID = -3725620407788489160L; public Dimension getSize() { return new Dimension(550, 200); } public Dimension getPreferredSize() { return new Dimension(550, 200); } public Dimension getMinimumSize() { return new Dimension(550, 200); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setFont(new Font("Serif", Font.PLAIN, 20)); g2.setColor(Color.BLACK); g2.drawString("Original string:", 100, 80); g2.drawString("Normalized string:", 100, 120); g2.setFont(new Font("Serif", Font.BOLD, 24)); // output of the original sample selected from the ComboBox String original_string = templateValues.get(normalizationTemplate.getSelectedItem()); g2.drawString(original_string, 320, 80); // normalization and output of the normalized string String normalized_string; java.text.Normalizer.Form currentForm = formValues.get(formComboBox.getSelectedItem()); normalized_string = Normalizer.normalize(original_string, currentForm); g2.drawString(normalized_string, 320, 120); } }; setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(paintingComponent); JPanel controls = new JPanel(); controls.setLayout(new BoxLayout(controls, BoxLayout.X_AXIS)); controls.add(new Label("Normalization Form: ")); controls.add(formComboBox); controls.add(new Label("Normalization Template:")); controls.add(normalizationTemplate); add(controls); formComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { paintingComponent.repaint(); } }); normalizationTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { paintingComponent.repaint(); } }); }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/* w ww . jav a2 s .com*/ 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); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. 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); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. 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); } }); // Setting the Slider sets that font into the textfield. 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:EditorPaneExample10.java
public EditorPaneExample10() { super("JEditorPane Example 10"); 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;//from ww w . j a va 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.github.cric.app.ui.SettingPanel.java
public SettingPanel(SettingFrame parent, ScoreService scoreService) { super();//from w ww . j a va2 s .co m this.parentFrame = parent; this.scoreService = scoreService; this.persistingService = new PersistingService(); Settings currentSettings = persistingService.getSettings(); System.setProperty(API_KEY_PROP, currentSettings.getApiKey()); this.matchesCombo = new JComboBox<>(); this.apiKeyField = textField(currentSettings.getApiKey(), false); this.popupTimeField = textField(Integer.toString(currentSettings.getPopupTime()), true); this.popupFreuencyField = textField(Integer.toString(currentSettings.getPopupFrequency()), true); this.submitButton = submitButton(); this.msgLabel = new JLabel(" "); initUI(); }
From source file:ZipTest.java
public ZipTestFrame() { setTitle("ZipTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // add the menu and the Open and Exit menu items JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); menu.add(openItem);//from ww w.j a va 2 s. com openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); int r = chooser.showOpenDialog(ZipTestFrame.this); if (r == JFileChooser.APPROVE_OPTION) { zipname = chooser.getSelectedFile().getPath(); fileCombo.removeAllItems(); scanZipFile(); } } }); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); menuBar.add(menu); setJMenuBar(menuBar); // add the text area and combo box fileText = new JTextArea(); fileCombo = new JComboBox(); fileCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { loadZipFile((String) fileCombo.getSelectedItem()); } }); add(fileCombo, BorderLayout.SOUTH); add(new JScrollPane(fileText), BorderLayout.CENTER); }