List of usage examples for javax.swing JTextField JTextField
public JTextField(int columns)
TextField
with the specified number of columns. From source file:Main.java
public static void main(String[] argv) throws Exception { JTextField component = new JTextField(10); JTextField component1 = new JTextField(10); component.addFocusListener(new MyFocusListener()); component1.addFocusListener(new MyFocusListener()); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(component1);/* ww w .java2 s . c om*/ f.add(component); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { displayMessage("Focus gained", e); }//from w w w. ja v a 2 s .c o m public void focusLost(FocusEvent e) { displayMessage("Focus lost", e); } void displayMessage(String prefix, FocusEvent e) { System.out.println(e.getID() == FocusEvent.FOCUS_LOST); } }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { displayMessage("Focus gained", e); }/*from ww w.j a v a 2s . com*/ public void focusLost(FocusEvent e) { displayMessage("Focus lost", e); } void displayMessage(String prefix, FocusEvent e) { System.out.println(e.getID() == FocusEvent.FOCUS_LAST); } }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { displayMessage("Focus gained", e); }/*from w ww . jav a 2s . co m*/ public void focusLost(FocusEvent e) { displayMessage("Focus lost", e); } void displayMessage(String prefix, FocusEvent e) { System.out.println(e.getID() == FocusEvent.FOCUS_FIRST); } }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { displayMessage("Focus gained", e); }//w ww .j av a 2s.c om public void focusLost(FocusEvent e) { displayMessage("Focus lost", e); } void displayMessage(String prefix, FocusEvent e) { System.out.println(e.paramString()); } }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); 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. ja v a2s .co 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:Main.java
public static void main(String[] a) { final JTextField textField = new JTextField(5); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { }/*from w w w . j av a2 s . co m*/ public void focusLost(FocusEvent e) { if (!e.isTemporary()) { String content = textField.getText(); if (!content.equals("a")) { System.out.println("illegal value! " + content); SwingUtilities.invokeLater(new FocusGrabber(textField)); } } } }); JFrame frame = new JFrame(); frame.add(textField, BorderLayout.CENTER); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextField account = new JTextField(10); JPanel accountPanel = new JPanel(new GridLayout()); accountPanel.add(account);/*from ww w .j a va 2 s. c om*/ accountPanel.setBorder(new TitledBorder("Account")); String[] firstDigitList = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; JLabel firstDigitListLabel = new JLabel("Leading Digit Change"); JPanel firstDigitListPanel = new JPanel(new BorderLayout(4, 2)); firstDigitListPanel.add(firstDigitListLabel, BorderLayout.WEST); JComboBox firstDigitCombo = new JComboBox(firstDigitList); firstDigitListPanel.add(firstDigitCombo); firstDigitCombo.setSelectedIndex(0); firstDigitListPanel.setBorder(new TitledBorder("LDC")); JPanel panel = new JPanel(); panel.add(accountPanel); panel.add(firstDigitListPanel); int result = JOptionPane.showConfirmDialog(null, panel, "Please Enter Values", JOptionPane.OK_CANCEL_OPTION); }
From source file:UsingFocusListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField("A TextField"); textField.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { displayMessage("Focus gained", e); }//from w ww . ja v a 2 s. c om public void focusLost(FocusEvent e) { displayMessage("Focus lost", e); } void displayMessage(String prefix, FocusEvent e) { System.out.println(prefix + (e.isTemporary() ? " (temporary):" : ":") + e.getComponent().getClass().getName() + "; Opposite component: " + (e.getOppositeComponent() != null ? e.getOppositeComponent().getClass().getName() : "null")); } }); frame.add(textField, "North"); frame.add(new JTextField(), "South"); frame.setSize(300, 200); 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//from ww w .j a va 2 s .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); }