List of usage examples for javax.swing JTextField JTextField
public JTextField()
TextField
. 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 w w . j a va 2 s . co m*/ frame.setSize(250, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { Locale locale = Locale.getDefault(); ResourceBundle rb = ResourceBundle.getBundle("MyResources", locale); JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("I18N Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 2)); frame.add(new JLabel(rb.getString("userName"))); frame.add(new JTextField()); frame.add(new JLabel(rb.getString("password"))); frame.add(new JPasswordField()); frame.add(new JButton(rb.getString("login"))); frame.pack();//from ww w . j a v a 2 s .c om frame.setVisible(true); }
From source file:LoadSave.java
public static void main(String args[]) { final String filename = "text.out"; JFrame frame = new JFrame("Loading/Saving Example"); Container content = frame.getContentPane(); final JTextField textField = new JTextField(); content.add(textField, BorderLayout.NORTH); JPanel panel = new JPanel(); Action loadAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { doLoadCommand(textField, filename); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace();/*from w w w.j a v a 2s. c o m*/ } } }; loadAction.putValue(Action.NAME, "Load"); JButton loadButton = new JButton(loadAction); panel.add(loadButton); Action saveAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { doSaveCommand(textField, filename); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }; saveAction.putValue(Action.NAME, "Save"); JButton saveButton = new JButton(saveAction); panel.add(saveButton); Action clearAction = new AbstractAction() { { putValue(Action.NAME, "Clear"); } public void actionPerformed(ActionEvent e) { textField.setText(""); } }; JButton clearButton = new JButton(clearAction); panel.add(clearButton); content.add(panel, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Key Text Sample"); KeyTextComponent keyTextComponent = new KeyTextComponent(); final JTextField textField = new JTextField(); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { String keyText = actionEvent.getActionCommand(); textField.setText(keyText);/* ww w.j a v a 2 s . c o m*/ } }; keyTextComponent.addActionListener(actionListener); frame.add(keyTextComponent, BorderLayout.CENTER); frame.add(textField, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:OffsetSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Offset Example"); Container content = frame.getContentPane(); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); final JTextField textField = new JTextField(); label.setLabelFor(textField);/*from w ww. java2s. c o m*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); content.add(panel, BorderLayout.NORTH); JButton button = new JButton("Get Offset"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Offset: " + textField.getScrollOffset()); System.out.println("Visibility: " + textField.getHorizontalVisibility()); BoundedRangeModel model = textField.getHorizontalVisibility(); int extent = model.getExtent(); textField.setScrollOffset(extent); } }; button.addActionListener(actionListener); content.add(button, BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from w ww .j av a2s .c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); TreeCellEditor comboEditor = new DefaultCellEditor(new JTextField()); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); 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(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//w ww . j a v a 2 s. c om DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); System.out.println(comboEditor.getClickCountToStart()); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); 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(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from w w w .j a va 2 s . c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); comboEditor.cancelCellEditing(); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); 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(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);//from w ww . ja v a 2 s. c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); comboEditor.setClickCountToStart(3); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); 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(final String args[]) { JFrame frame = new JFrame("Editable Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.setEditable(true);/*w w w . jav a2 s. c o m*/ DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); DefaultCellEditor comboEditor = new DefaultCellEditor(new JTextField()); System.out.println(comboEditor.getComponent()); TreeCellEditor editor = new DefaultTreeCellEditor(tree, renderer, comboEditor); tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }