List of usage examples for javax.swing JTextField JTextField
public JTextField()
TextField
. From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Box rowOne = Box.createHorizontalBox(); rowOne.add(new JLabel("Username")); rowOne.add(new JTextField()); Box rowTwo = Box.createHorizontalBox(); AccessibleContext context = rowTwo.getAccessibleContext(); System.out.println(context);/*ww w . jav a2s. c o m*/ rowTwo.add(new JLabel("Password")); rowTwo.add(new JPasswordField()); f.add(rowOne, BorderLayout.NORTH); f.add(rowTwo, BorderLayout.SOUTH); f.setSize(300, 200); 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); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);//from ww w . j a v a2 s.co m frame.add(label, BorderLayout.WEST); frame.add(textField, BorderLayout.CENTER); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.PAGE_START); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);// w ww . j av a 2 s . co m 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); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.LINE_START); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);//from ww w . ja va2 s . co m 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); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.PAGE_END); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);// w w w . j a va 2 s .c om 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); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.LINE_END); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);//from w ww. j a v a 2 s . c o m 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); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LINE_ENDS); frame.add(outerPanel);//from w w w . j ava2s. c om 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); JPanel outerPanel = new JPanel(new BorderLayout()); JPanel topPanel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name:"); JTextField text = new JTextField(); topPanel.add(label, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(text, BorderLayout.CENTER); outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE); frame.add(outerPanel);/* ww w . j a v a 2s . c om*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:AddingActionCommandActionListenerSample.java
public static void main(String args[]) { final JFrame frame = new JFrame("Default Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); frame.add(new JTextField(), BorderLayout.SOUTH); InputVerifier verifier = new InputVerifier() { public boolean verify(JComponent input) { final JTextComponent source = (JTextComponent) input; String text = source.getText(); if ((text.length() != 0) && !(text.equals("Exit"))) { JOptionPane.showMessageDialog(frame, "Can't leave.", "Error Dialog", JOptionPane.ERROR_MESSAGE); return false; } else { return true; }//from www .j a v a 2 s. c o m } }; textField.setInputVerifier(verifier); frame.setSize(250, 150); frame.setVisible(true); }
From source file:CutPasteSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cut/Paste Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField textField = new JTextField(); frame.add(textField, BorderLayout.NORTH); Action actions[] = textField.getActions(); Action cutAction = findAction(actions, DefaultEditorKit.cutAction); Action copyAction = findAction(actions, DefaultEditorKit.copyAction); Action pasteAction = findAction(actions, DefaultEditorKit.pasteAction); JPanel panel = new JPanel(); frame.add(panel, BorderLayout.SOUTH); JButton cutButton = new JButton(cutAction); cutButton.setText("Cut"); panel.add(cutButton);//from ww w .j ava 2 s.c om JButton copyButton = new JButton(copyAction); copyButton.setText("Copy"); panel.add(copyButton); JButton pasteButton = new JButton(pasteAction); pasteButton.setText("Paste"); panel.add(pasteButton); frame.setSize(250, 250); frame.setVisible(true); }