List of usage examples for javax.swing JTextField JTextField
public JTextField(String text, int columns)
TextField
initialized with the specified text and columns. From source file:SpringDemo4.java
public static void main(String[] args) { JFrame frame = new JFrame("SpringDemo4"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout);/* w ww . j av a 2s . c o m*/ // Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); // Adjust constraints for the label so it's at (5,5). SpringLayout.Constraints labelCons = layout.getConstraints(label); labelCons.setX(Spring.constant(5)); labelCons.setY(Spring.constant(5)); // Adjust constraints for the text field so it's at // (<label's right edge> + 5, 5). SpringLayout.Constraints textFieldCons = layout.getConstraints(textField); textFieldCons.setX(Spring.sum(Spring.constant(5), labelCons.getConstraint(SpringLayout.EAST))); textFieldCons.setY(Spring.constant(5)); // Adjust constraints for the content pane. setContainerSize(contentPane, 5); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static JTextField createTextField(String text, int cols) { final JTextField b = new JTextField(text, cols); configureActiveComponent(b);//from ww w. j a va2 s .c o m return b; }
From source file:Main.java
public static JTextField createTextField(String text, int columns, ActionListener... listeners) { JTextField result = new JTextField(text, columns); for (ActionListener listener : listeners) { result.addActionListener(listener); }//from ww w.j a v a 2s . c o m return result; }
From source file:JTextFieldTest.java
public JTextFieldTest() { super("JTextField Test"); getContentPane().setLayout(new FlowLayout()); JTextField textField1 = new JTextField("1", 1); JTextField textField2 = new JTextField("22", 2); JTextField textField3 = new JTextField("333", 3); getContentPane().add(textField1);/* w ww.j av a 2 s. c om*/ getContentPane().add(textField2); getContentPane().add(textField3); setSize(300, 170); setVisible(true); }
From source file:Main.java
public Main() { super("JTextField Test"); getContentPane().setLayout(new FlowLayout()); JTextField textField1 = new JTextField("1", 1); JTextField textField2 = new JTextField("22", 2); JTextField textField3 = new JTextField("333", 3); getContentPane().add(textField1);//from www . j ava 2 s . c o m getContentPane().add(textField2); getContentPane().add(textField3); setSize(300, 170); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField field1 = new JTextField("Life's a drag", 20); JTextField field2 = new JTextField("and then you drop", 20); field1.setDragEnabled(true);/*from w w w . j ava 2s . c om*/ field2.setDragEnabled(true); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(field1); content.add(field2); pack(); }
From source file:DragDropText.java
public DragDropText() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField field1 = new JTextField("Life's a drag", 20); JTextField field2 = new JTextField("and then you drop", 20); field1.setDragEnabled(true);//from ww w . j av a2 s . c om field2.setDragEnabled(true); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(field1); content.add(field2); pack(); }
From source file:MainClass.java
public MainClass() { Box box = new Box(BoxLayout.Y_AXIS); box.add(new JButton("Test button")); box.add(new JSlider()); box.add(new JTextField("Text field with some text", 20)); box.add(new JButton("Another, bigger button")); getContentPane().add(box);//from ww w . j a v a 2 s .c om setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); }
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250);//from w w w . j a v a2 s . com dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path); panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:Main.java
protected void addFields(GridBagConstraints gbc) { JTextField field1 = new JTextField("0", 5); field1.setEnabled(false);//from w ww . j a v a 2 s . c o m gbc.anchor = GridBagConstraints.CENTER; gbc.gridx++; add(field1, gbc); gbc.gridx++; gbc.insets = new Insets(0, 4, 0, 4); add(new JLabel("+"), gbc); JTextField field2 = new JTextField(5); gbc.gridx++; add(field2, gbc); }