List of usage examples for javax.swing JTextField setText
@BeanProperty(bound = false, description = "the text of this component") public void setText(String t)
TextComponent
to the specified text. From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createDeelnemersPanel() { JPanel panel = new JPanel(false); panel.setBackground(Color.BLACK); //panel.setLayout(new GridLayout(1, 0)); panel.setLayout(new BorderLayout()); JPanel innerPanel = new JPanel(); JLabel lbAanwezig = new JLabel("Deelnemers: "); innerPanel.add(lbAanwezig, BorderLayout.NORTH); tfAanwezig = new JLabel(Integer.toString(status.deelnemers.aantalAanwezig()), 10); innerPanel.add(tfAanwezig, BorderLayout.NORTH); //innerPanel.setLayout(new GridLayout(1, 0)); innerPanel.add(new JLabel("Naam:"), BorderLayout.NORTH); JTextField deelnemer = new JTextField(15); ArrayList<String> words = new ArrayList<>(); if (status.OSBOSpelers != null) { for (Speler s : status.OSBOSpelers.values()) { words.add(s.getNaam().trim()); words.add(Integer.toString(s.getKnsbnummer())); }//from w w w. j a v a 2 s . c o m } @SuppressWarnings("unused") Suggesties suggesties = new Suggesties(deelnemer, this, words, 2); innerPanel.add(deelnemer, BorderLayout.NORTH); deelnemer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); JButton btVoegToe = new JButton("Voeg toe"); btVoegToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); innerPanel.add(btVoegToe); panel.add(innerPanel); // panel_deelnemers.add(new JLabel("Deelnemers IJSCO toernooi")); deelnemersModel = new DeelnemersModel(panel, status.deelnemers); JTable deelnemersTabel = new JTable(deelnemersModel) { private static final long serialVersionUID = -8293073016982337108L; @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); DeelnemersModel model = (DeelnemersModel) getModel(); // Tooltip if (c instanceof JComponent) { ((JComponent) c) .setToolTipText(model.getToolTip(convertRowIndexToModel(row), column).toString()); } // Alternate row color if (!isRowSelected(row)) { c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY); } // Highlight overruled entries if (status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam() || status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam()) { c.setForeground(Color.BLUE); } else { c.setForeground(Color.BLACK); } return c; } }; deelnemersTabel.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { status.groepen = null; status.schemas = null; status.schema = null; groepenText.setText(""); schemaModel.setSchemas(null); schemaModel.fireTableDataChanged(); if (status.deelnemers != null && tfAanwezig != null) { tfAanwezig.setText(Integer.toString(status.deelnemers.aantalAanwezig())); } panel.repaint(); } }); deelnemersTabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { logger.log(Level.INFO, "MouseEvent on table fired, type : " + e.toString()); logger.log(Level.INFO, "Popup trigger? : " + e.isPopupTrigger()); if (e.isPopupTrigger()) { int row = deelnemersTabel.rowAtPoint(e.getPoint()); JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Bewerk speler"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Bewerk Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); BewerkSpelerDialoog rd = new BewerkSpelerDialoog(new JFrame(), "Bewerk Speler", s, deelnemersModel); rd.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { System.out.println("closing..."); } }); rd.setVisible(true); } }); popup.add(menuItem); menuItem = new JMenuItem("Verwijder Speler"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Verwijder Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); status.deelnemers.remove(s); deelnemersModel.fireTableDataChanged(); } }); popup.show(e.getComponent(), e.getX(), e.getY()); } } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(deelnemersTabel); innerPanel.add(scrollPane, BorderLayout.CENTER); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(deelnemersModel); deelnemersTabel.setRowSorter(sorter); innerPanel.add(new JLabel("Filter op : ")); JTextField tfFilter = new JTextField(10); tfFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(tfFilter); JButton btPasToe = new JButton("Apply"); btPasToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(btPasToe); JButton btWis = new JButton("Wis"); btWis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { tfFilter.setText(""); logger.log(Level.INFO, "Wis filter"); sorter.setRowFilter(null); } }); innerPanel.add(btWis); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(0), 30); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(1), 55); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(2), 170); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(3), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(4), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(5), 30); Utils.fixedComponentSize(scrollPane, 400, 580); return panel; }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Add a new Text Field//from www .ja v a 2 s . c om * * @param container - parent container * @param name - name of text field * @param initialValue - initial value of text field * @param mnemonic - mnemonic key * @param tooltip - tool tip for field * @param suffix - suffix text for field * @param labelWidth - label width * @param placement - TableLayout placement * @param debug - turn on/off red debug borders * @return JTextField */ public static JTextField addTextField(Container container, String name, String initialValue, int mnemonic, String tooltip, String suffix, double labelWidth, String placement, boolean debug) { double[][] size = null; JPanel panel = new JPanel(); panel.setOpaque(false); if (suffix.equals("")) size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } }; else size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } }; TableLayout layout = new TableLayout(size); panel.setLayout(layout); JLabel label = new JLabel(name); label.setDisplayedMnemonic(mnemonic); JTextField result = new JTextField(20); label.setLabelFor(result); label.setOpaque(false); result.setToolTipText(tooltip); if (initialValue != null) result.setText(initialValue); panel.add(label, "0, 0, r, c"); panel.add(result, "1, 0, f, c"); if (suffix.length() != 0) { JLabel suffixLabel = new JLabel(" " + suffix); panel.add(suffixLabel, "2,0, l, c"); } if (debug == true) panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), panel.getBorder())); container.add(panel, placement); return result; }
From source file:openlr.mapviewer.coding.ui.AbstractCodingOptionsDialog.java
/** * Sets up an input field of the form/* ww w . ja v a2 s . c om*/ * * @param propKey * The full configuration property key this field relates to * @param value * The initial value to set * @return The set-up input field */ private JTextField createInputField(final String propKey, final String value) { final JTextField valueField = new JTextField(); valueField.setText(value); valueField.setHorizontalAlignment(JTextField.RIGHT); valueField.setPreferredSize(new Dimension(WIDT_INPUT_FIELD, valueField.getHeight())); optionsTextFields.put(propKey, valueField); final String defaultValue = defaultConfig.getString(propKey); valueField.getDocument().addDocumentListener(new VisualPropertyChangeListener(valueField, defaultValue)); if (!defaultValue.equals(value)) { valueField.setBackground(VisualPropertyChangeListener.COLOR_FIELD_VALUE_DIFF_DEFAULT); } StringBuilder toolTip = new StringBuilder(); toolTip.append(propKey).append(", default: ").append(defaultValue); valueField.setToolTipText(toolTip.toString()); afterInputFieldCreation(propKey, valueField); return valueField; }
From source file:org.accada.hal.impl.sim.GraphicSimulator.java
/** * shows the dialog menu to add a new antenna *//*w w w. j a v a 2 s. c o m*/ private void showAddAntennaDialog() { Point pos = new Point(); pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2; pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2; if (newAntennaDialog == null) { newAntennaDialog = new JDialog(this, guiTextConfig.getString("AddNewAntennaDialogTitle"), true); newAntennaDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight")); newAntennaDialog.setLayout(new BorderLayout()); // input fields JLabel idLabel = new JLabel(guiTextConfig.getString("AntennaIdLabel") + ": "); final JTextField idField = new JTextField(); JPanel inputFields = new JPanel(); inputFields.setLayout(new GridLayout(2, 2)); inputFields.add(idLabel); inputFields.add(idField); // cancel button JButton cancelButton = new JButton(guiTextConfig.getString("CancelButton")); cancelButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { newAntennaDialog.setVisible(false); idField.setText(""); } }); // add button JButton addButton = new JButton(guiTextConfig.getString("AddButton")); addButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { newAntennaDialog.setVisible(false); createNewAntenna(idField.getText()); idField.setText(""); } }); // buttons panel JPanel buttons = new JPanel(); buttons.add(addButton); buttons.add(cancelButton); newAntennaDialog.add(inputFields, BorderLayout.CENTER); newAntennaDialog.add(buttons, BorderLayout.SOUTH); newAntennaDialog.getRootPane().setDefaultButton(addButton); } newAntennaDialog.setLocation(pos); newAntennaDialog.setVisible(true); }
From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java
/** * shows the dialog menu to add a new antenna *//*ww w.ja va 2 s . c o m*/ private void showAddAntennaDialog() { Point pos = new Point(); pos.x = jLayeredPane.getLocationOnScreen().x + (jLayeredPane.getWidth() - getProperty("DialogWindowWidth")) / 2; pos.y = jLayeredPane.getLocationOnScreen().y + (jLayeredPane.getHeight() - getProperty("DialogWindowHeight")) / 2; if (newAntennaDialog == null) { newAntennaDialog = new JDialog(this, guiText.getString("AddNewAntennaDialogTitle"), true); newAntennaDialog.setSize(getProperty("DialogWindowWidth"), getProperty("DialogWindowHeight")); newAntennaDialog.setLayout(new BorderLayout()); // input fields JLabel idLabel = new JLabel(guiText.getString("AntennaIdLabel") + ": "); final JTextField idField = new JTextField(); JPanel inputFields = new JPanel(); inputFields.setLayout(new GridLayout(2, 2)); inputFields.add(idLabel); inputFields.add(idField); // cancel button JButton cancelButton = new JButton(guiText.getString("CancelButton")); cancelButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { newAntennaDialog.setVisible(false); idField.setText(""); } }); // add button JButton addButton = new JButton(guiText.getString("AddButton")); addButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { newAntennaDialog.setVisible(false); createNewAntenna(idField.getText()); idField.setText(""); } }); // buttons panel JPanel buttons = new JPanel(); buttons.add(addButton); buttons.add(cancelButton); newAntennaDialog.add(inputFields, BorderLayout.CENTER); newAntennaDialog.add(buttons, BorderLayout.SOUTH); newAntennaDialog.getRootPane().setDefaultButton(addButton); } newAntennaDialog.setLocation(pos); newAntennaDialog.setVisible(true); }
From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java
protected void initBindings(BindingBuilder bindingBuilder) { initOutputFolder();//from ww w. ja v a2s . c o m JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder(); JButton outputSelect = ((GeneratorControllerPanel) getView()).getSelectOutputFolder(); outputFolder.setText(getOutputPath()); bindingBuilder.bindToAction(outputSelect, "selectOutputFolderAction()"); bindingBuilder.bindToTextField(outputFolder, "outputPath"); }
From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java
/** * An action method that pops up a file chooser dialog to pick the * generation directory./*ww w . jav a 2 s. c o m*/ */ public void selectOutputFolderAction() { JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder(); String currentDir = outputFolder.getText(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); // guess start directory if (!Util.isEmptyString(currentDir)) { chooser.setCurrentDirectory(new File(currentDir)); } else { FSPath lastDir = Application.getInstance().getFrameController().getLastDirectory(); lastDir.updateChooser(chooser); } int result = chooser.showOpenDialog(getView()); if (result == JFileChooser.APPROVE_OPTION) { File selected = chooser.getSelectedFile(); // update model String path = selected.getAbsolutePath(); outputFolder.setText(path); setOutputPath(path); } }
From source file:org.broad.igv.ui.action.SetTrackHeightMenuAction.java
/** * Method description//from w w w.ja va 2 s. c o m */ final public void doSetTrackHeight() { boolean doRefresh = false; try { JPanel container = new JPanel(); JLabel trackHeightLabel = new JLabel("Track Height (pixels)"); JTextField trackHeightField = new JTextField(); Dimension preferredSize = trackHeightField.getPreferredSize(); trackHeightField.setPreferredSize(new Dimension(50, (int) preferredSize.getHeight())); container.add(trackHeightLabel); container.add(trackHeightField); int repTrackHeight = getRepresentativeTrackHeight(); trackHeightField.setText(String.valueOf(repTrackHeight)); int status = JOptionPane.showConfirmDialog(mainFrame.getMainFrame(), container, "Set Track Height", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); if ((status == JOptionPane.CANCEL_OPTION) || (status == JOptionPane.CLOSED_OPTION)) { return; } try { int newTrackHeight = Integer.parseInt(trackHeightField.getText().trim()); IGV.getInstance().setAllTrackHeights(newTrackHeight); lastTrackHeight = newTrackHeight; doRefresh = true; } catch (NumberFormatException numberFormatException) { JOptionPane.showMessageDialog(mainFrame.getMainFrame(), "Track height must be an integer number."); } } finally { // Refresh view if (doRefresh) { // Update the state of the current tracks for drawing purposes mainFrame.doRefresh(); } mainFrame.resetStatusMessage(); } }
From source file:org.codinjutsu.tools.jenkins.view.BuildParamDialog.java
private JTextField createTextField(String defaultValue) { JTextField textField = new JTextField(); if (StringUtils.isNotEmpty(defaultValue)) { textField.setText(defaultValue); }/*from w w w. j a v a 2 s .com*/ return textField; }
From source file:org.eclipse.wb.internal.swing.preferences.laf.LafPreferencePage.java
/** * Creates {@link EmbeddedSwingComposite} with some Swing components to show it using different * LAFs./* w w w . j ava2s . com*/ */ private void createPreviewArea(Group previewGroup) { try { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); EmbeddedSwingComposite awtComposite = new EmbeddedSwingComposite(previewGroup, SWT.NONE) { @Override protected JComponent createSwingComponent() { // create the JRootPane JRootPane rootPane = new JRootPane(); { JMenuBar menuBar = new JMenuBar(); rootPane.setJMenuBar(menuBar); { JMenu mnFile = new JMenu(Messages.LafPreferencePage_previewFile); menuBar.add(mnFile); { JMenuItem mntmNew = new JMenuItem(Messages.LafPreferencePage_previewNew); mnFile.add(mntmNew); } { JMenuItem mntmExit = new JMenuItem(Messages.LafPreferencePage_previewExit); mnFile.add(mntmExit); } } { JMenu mnView = new JMenu(Messages.LafPreferencePage_previewView); menuBar.add(mnView); { JMenuItem mntmCommon = new JMenuItem(Messages.LafPreferencePage_previewCommon); mnView.add(mntmCommon); } } } GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0E-4 }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0E-4 }; rootPane.getContentPane().setLayout(gridBagLayout); { JLabel lblLabel = new JLabel(Messages.LafPreferencePage_previewLabel); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.gridx = 0; gbc.gridy = 0; rootPane.getContentPane().add(lblLabel, gbc); } { JButton btnPushButton = new JButton(Messages.LafPreferencePage_previewButton); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 0; rootPane.getContentPane().add(btnPushButton, gbc); } { JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] { Messages.LafPreferencePage_previewCombo, "ComboBox Item 1", "ComboBox Item 2" })); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 1; rootPane.getContentPane().add(comboBox, gbc); } { JRadioButton rdbtnRadioButton = new JRadioButton(Messages.LafPreferencePage_previewRadio); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 1; rootPane.getContentPane().add(rdbtnRadioButton, gbc); } { JCheckBox chckbxCheckbox = new JCheckBox(Messages.LafPreferencePage_previewCheck); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 5); gbc.gridx = 0; gbc.gridy = 2; rootPane.getContentPane().add(chckbxCheckbox, gbc); } { JTextField textField = new JTextField(); textField.setText(Messages.LafPreferencePage_previewTextField); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 1; gbc.gridy = 2; rootPane.getContentPane().add(textField, gbc); } return rootPane; } }; awtComposite.populate(); // restore current laf UIManager.put("ClassLoader", currentLookAndFeel.getClass().getClassLoader()); UIManager.setLookAndFeel(currentLookAndFeel); } catch (Throwable e) { DesignerPlugin.log(e); } }