List of usage examples for javax.swing JTextField getDocument
public Document getDocument()
From source file:MyDocumentListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); textField.getDocument().addDocumentListener(new MyDocumentListener()); textField.getDocument().putProperty("name", "Text Field"); frame.add(textField);/*from w w w .j a v a 2 s . c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { JTextField field = new JTextField(30); ((AbstractDocument) (field.getDocument())).setDocumentFilter(new DocumentFilter() { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { System.out.println("insert"); fb.insertString(offset, string.toUpperCase(), attr); }/* w w w . j a va 2 s . c o m*/ public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { System.out.println("replace"); fb.replace(offset, length, string.toUpperCase(), attr); } }); JFrame frame = new JFrame("User Information"); frame.getContentPane().add(field); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JTextField field = new JTextField(30); ((AbstractDocument) (field.getDocument())).setDocumentFilter(new DocumentFilter() { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { System.out.println("insert"); fb.insertString(offset, string.toUpperCase(), attr); }//w w w. j a v a2 s .c o m public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { System.out.println("replace"); fb.replace(offset, length, string.toUpperCase(), attr); } }); JFrame frame = new JFrame("User Information"); frame.getContentPane().add(field); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:IntegerRangeDocumentFilter.java
public static void main(String args[]) { JFrame frame = new JFrame("Range Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textFieldOne = new JTextField(); Document textDocOne = textFieldOne.getDocument(); DocumentFilter filterOne = new IntegerRangeDocumentFilter(); ((AbstractDocument) textDocOne).setDocumentFilter(filterOne); frame.add(textFieldOne);/*from ww w . j a v a 2 s . c o m*/ frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel contentPane = new JPanel(); JTextField tField = new JTextField(10); ((AbstractDocument) tField.getDocument()).setDocumentFilter(new MyDocumentFilter()); contentPane.add(tField);// w ww . j av a2s . co m frame.setContentPane(contentPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel mainPanel = new JPanel(); JTextField field = new JTextField(20); JTextField field1 = new JTextField(20); field.getDocument().addDocumentListener(new DocumentListener() { @Override/* ww w .j av a 2s . c om*/ public void changedUpdate(DocumentEvent e) { updateLabel(e); } @Override public void insertUpdate(DocumentEvent e) { updateLabel(e); } @Override public void removeUpdate(DocumentEvent e) { updateLabel(e); } private void updateLabel(DocumentEvent e) { field1.setText(field.getText()); } }); mainPanel.setLayout(new GridLayout(1, 0, 10, 0)); mainPanel.add(field); mainPanel.add(field1); JFrame frame = new JFrame(); frame.getContentPane().add(mainPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:UpcaseFilter.java
public static void main(String[] args) { DocumentFilter dfilter = new UpcaseFilter(); JTextArea jta = new JTextArea(); JTextField jtf = new JTextField(); ((AbstractDocument) jta.getDocument()).setDocumentFilter(dfilter); ((AbstractDocument) jtf.getDocument()).setDocumentFilter(dfilter); JFrame frame = new JFrame("UpcaseFilter"); frame.getContentPane().add(jta, java.awt.BorderLayout.CENTER); frame.getContentPane().add(jtf, java.awt.BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 120);/* ww w. j ava 2 s . c o m*/ frame.setVisible(true); }
From source file:UpcaseFilter.java
public static void main(String[] args) { DocumentFilter dfilter = new UpcaseFilter(); JTextArea jta = new JTextArea(); JTextField jtf = new JTextField(); ((AbstractDocument) jta.getDocument()).setDocumentFilter(dfilter); ((AbstractDocument) jtf.getDocument()).setDocumentFilter(dfilter); JFrame frame = new JFrame("UpcaseFilter"); frame.getContentPane().add(jta, "Center"); frame.getContentPane().add(jtf, "South"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 120);// w w w. j ava 2 s.c o m frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Range Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JLabel("Range: 0-255")); JTextField textFieldOne = new JTextField(); Document textDocOne = textFieldOne.getDocument(); DocumentFilter filterOne = new IntegerRangeDocumentFilter(0, 255); ((AbstractDocument) textDocOne).setDocumentFilter(filterOne); frame.add(textFieldOne);/*from w ww . j a va 2 s . c o m*/ frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame("Text Field Elements"); JTextField tf = new JTextField(32); tf.setText("That's one small step for man..."); f.getContentPane().add(tf);//from ww w . j a v a 2 s . co m f.pack(); f.setVisible(true); ((AbstractDocument) tf.getDocument()).dump(System.out); }