List of usage examples for javax.swing JTextField JTextField
public JTextField()
TextField
. From source file:TreeEditJTextField.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); JTextField textField = new JTextField(); TreeCellEditor editor = new DefaultCellEditor(textField); tree.setEditable(true);/*from www. j a v a 2s . com*/ tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); JPanel topPane = new JPanel(); JPanel midPane = new JPanel(); JPanel panesHolder = new JPanel(); JLabel label = new JLabel("Top label"); JTextField field = new JTextField(); field.setColumns(5);//w w w. j a v a 2 s.co m topPane.setLayout(new FlowLayout()); midPane.setLayout(new GridLayout(3, 2)); topPane.add(label); topPane.add(field); midPane.add(new JButton("Button 1")); midPane.add(new JButton("Button 2")); midPane.add(new JButton("A")); midPane.add(new JButton("H")); midPane.add(new JButton("I")); midPane.add(new JButton("T")); panesHolder.setLayout(new BoxLayout(panesHolder, BoxLayout.Y_AXIS)); panesHolder.add(topPane); panesHolder.add(midPane); frame.add(panesHolder); frame.setSize(400, 300); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:DefaultSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Default Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); }//from w ww . jav a 2s .c o m }; JPanel panel = new JPanel(); JButton defaultButton = new JButton("Default Button"); defaultButton.addActionListener(actionListener); panel.add(defaultButton); JButton otherButton = new JButton("Other Button"); otherButton.addActionListener(actionListener); panel.add(otherButton); frame.add(panel, BorderLayout.SOUTH); Keymap keymap = textField.getKeymap(); KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); keymap.removeKeyStrokeBinding(keystroke); frame.getRootPane().setDefaultButton(defaultButton); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);//w w w .j a v a2 s . c o m panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Default Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); JPanel panel = new JPanel(); JButton defaultButton = new JButton("Default Button"); defaultButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); }//from w ww. ja v a2s. co m }); panel.add(defaultButton); JButton otherButton = new JButton("Other Button"); otherButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand() + " selected"); } }); panel.add(otherButton); frame.add(panel, BorderLayout.SOUTH); Keymap keymap = textField.getKeymap(); KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false); keymap.removeKeyStrokeBinding(keystroke); frame.getRootPane().setDefaultButton(defaultButton); frame.setSize(250, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Popup Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { int dotPosition = textField.getCaretPosition(); Rectangle popupLocation = null; try { popupLocation = textField.modelToView(dotPosition); } catch (BadLocationException e) { e.printStackTrace();//from w w w .ja v a2s . com } System.out.println(popupLocation); } }; KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, 0, false); textField.registerKeyboardAction(actionListener, keystroke, JComponent.WHEN_FOCUSED); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JPasswordField Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new BorderLayout()); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Box rowTwo = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); rowTwo.add(new JPasswordField()); content.add(rowOne, BorderLayout.NORTH); content.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200);//from www.j a va 2 s .c o m f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);/*from w w w.j av a2 s . c o m*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); textField.setText("Loooooooooooooooooooooooooooooooooooooooooooooooooooooooong"); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); System.out.println("extent:" + extent); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel userPanel = new JPanel(new BorderLayout()); JLabel userLabel = new JLabel("Username: "); userLabel.setDisplayedMnemonic(KeyEvent.VK_U); JTextField userTextField = new JTextField(); userLabel.setLabelFor(userTextField); userPanel.add(userLabel, BorderLayout.WEST); userPanel.add(userTextField, BorderLayout.CENTER); JPanel passPanel = new JPanel(new BorderLayout()); JLabel passLabel = new JLabel("Password: "); passLabel.setDisplayedMnemonic('p'); JPasswordField passTextField = new JPasswordField(); passLabel.setLabelFor(passTextField); passPanel.add(passLabel, BorderLayout.WEST); passPanel.add(passTextField, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); panel.add(userPanel, BorderLayout.NORTH); panel.add(passPanel, BorderLayout.SOUTH); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150);/* ww w .ja va 2 s .co m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel userPanel = new JPanel(new BorderLayout()); JLabel userLabel = new JLabel("Username: "); userLabel.setDisplayedMnemonic(KeyEvent.VK_U); JTextField userTextField = new JTextField(); userLabel.setLabelFor(userTextField); userPanel.add(userLabel, BorderLayout.WEST); userPanel.add(userTextField, BorderLayout.CENTER); System.out.println(userLabel.getDisplayedMnemonicIndex()); JPanel passPanel = new JPanel(new BorderLayout()); JLabel passLabel = new JLabel("Password: "); passLabel.setDisplayedMnemonic('p'); JPasswordField passTextField = new JPasswordField(); passLabel.setLabelFor(passTextField); passPanel.add(passLabel, BorderLayout.WEST); passPanel.add(passTextField, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); panel.add(userPanel, BorderLayout.NORTH); panel.add(passPanel, BorderLayout.SOUTH); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150);//from w ww . j a v a2s . c o m frame.setVisible(true); }