Java Code Examples for javax.swing.JTextField#getDocument()
The following examples show how to use
javax.swing.JTextField#getDocument() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFXProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if(document != null) { document.removeDocumentListener(listener); } JTextField editor = (JTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); document = editor.getDocument(); listener = new CellEditorDocumentListener(table.getModel(), row, column); document.addDocumentListener(listener); return editor; }
Example 2
Source File: TextFieldDataBind.java From iec61850bean with Apache License 2.0 | 5 votes |
@Override protected JComponent init() { inputField = new JTextField(); PlainDocument doc = (PlainDocument) inputField.getDocument(); doc.setDocumentFilter(filter); resetImpl(); return inputField; }
Example 3
Source File: ExternalSourcesViewer.java From visualvm with GNU General Public License v2.0 | 5 votes |
private static void insertParameter(JTextField textField, String parameter) { Document document = textField.getDocument(); int length = document.getLength(); int position = textField.getCaretPosition(); try { if (position > 0 && !" ".equals(document.getText(position - 1, 1))) // NOI18N parameter = " " + parameter; // NOI18N if (position < length - 1 && !" ".equals(document.getText(position, 1))) // NOI18N parameter = parameter + " "; // NOI18N textField.getDocument().insertString(position, parameter, null); } catch (BadLocationException ex) {} }
Example 4
Source File: JTextFieldFactory.java From WorldGrower with GNU General Public License v3.0 | 5 votes |
public static JTextField createIntegerOnlyJTextField() { JTextField textField = new JFormattedTextField(); PlainDocument doc = (PlainDocument) textField.getDocument(); doc.setDocumentFilter(new DocumentIntFilter()); setTextFieldProperties(textField); return textField; }
Example 5
Source File: DGetHostPort.java From portecle with GNU General Public License v2.0 | 4 votes |
/** * Initialize the dialog's GUI components. * * @param iOldHostPort The host+port to display initially */ private void initComponents(InetSocketAddress iOldHostPort) { getContentPane().setLayout(new BorderLayout()); JLabel jlHost = new JLabel(RB.getString("DGetHostPort.jlHost.text")); m_jtfHost = new JTextField(15); jlHost.setLabelFor(m_jtfHost); JLabel jlPort = new JLabel(RB.getString("DGetHostPort.jlPort.text")); m_jtfPort = new JTextField(DEFAULT_PORT, 5); Document doc = m_jtfPort.getDocument(); if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).setDocumentFilter(new IntegerDocumentFilter(m_jtfPort.getColumns())); } if (iOldHostPort != null) { m_jtfHost.setText(iOldHostPort.getHostName()); m_jtfPort.setText(String.valueOf(iOldHostPort.getPort())); } jlPort.setLabelFor(m_jtfPort); JPanel jpHostPort = new JPanel(new FlowLayout(FlowLayout.CENTER)); jpHostPort.add(jlHost); jpHostPort.add(m_jtfHost); jpHostPort.add(jlPort); jpHostPort.add(m_jtfPort); jpHostPort.setBorder(new EmptyBorder(5, 5, 5, 5)); JButton jbOK = getOkButton(false); JButton jbCancel = getCancelButton(); JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER)); jpButtons.add(jbOK); jpButtons.add(jbCancel); getContentPane().add(jpHostPort, BorderLayout.CENTER); getContentPane().add(jpButtons, BorderLayout.SOUTH); getRootPane().setDefaultButton(jbOK); initDialog(); }
Example 6
Source File: PollIntervalDialog.java From sql-developer-keepalive with MIT License | 4 votes |
private void initDialog() { textField = new JTextField(20); PlainDocument doc = (PlainDocument) textField.getDocument(); doc.setDocumentFilter(new NumberFilter()); Object[] controls = { "Specify poll interval (in seconds):", textField }; Object[] options = { OK_STRING, CANCEL_STRING }; optionPane = new JOptionPane(controls, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]); setContentPane(optionPane); addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent ce) { textField.requestFocusInWindow(); } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent e) { if (isVisible() && JOptionPane.VALUE_PROPERTY.equals(e.getPropertyName())) { Object value = optionPane.getValue(); if (value == JOptionPane.UNINITIALIZED_VALUE) { return; } switch (value.toString()) { case OK_STRING: String v = textField.getText(); if (checkValue(v)) { pollInterval = Integer.parseInt(v, 10); setVisible(false); } else { //to let PropertyChangeEvent fire next time the user presses button optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); } break; case CANCEL_STRING: pollInterval = null; setVisible(false); break; } } } }); }