List of usage examples for javax.swing JTextField setHorizontalAlignment
@BeanProperty(preferred = true, enumerationValues = { "JTextField.LEFT", "JTextField.CENTER", "JTextField.RIGHT", "JTextField.LEADING", "JTextField.TRAILING" }, description = "Set the field alignment to LEFT, CENTER, RIGHT, LEADING (the default) or TRAILING") public void setHorizontalAlignment(int alignment)
From source file:Main.java
public static void main(String[] argv) { JTextField textfield = new JTextField(10); textfield.setHorizontalAlignment(JTextField.RIGHT); }
From source file:Main.java
public static void main(String[] argv) { JTextField textfield = new JTextField(10); textfield.setHorizontalAlignment(JTextField.RIGHT); JOptionPane.showMessageDialog(null, textfield); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); 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(); textField.setHorizontalAlignment(JTextField.CENTER); label.setLabelFor(textField);//from w w w .j ava 2 s . co m panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); textField.setHorizontalAlignment(JTextField.CENTER); label.setLabelFor(textField);/*from w ww. ja v a2 s . c o m*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel, BorderLayout.NORTH); frame.setSize(250, 150); frame.setVisible(true); }
From source file:AlignmentSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = frame.getContentPane(); content.setLayout(new GridLayout(0, 1)); JTextField textField = new JTextField("Left"); textField.setHorizontalAlignment(JTextField.LEFT); content.add(textField);/*from ww w . jav a 2s . co m*/ textField = new JTextField("Center"); textField.setHorizontalAlignment(JTextField.CENTER); content.add(textField); textField = new JTextField("Right"); textField.setHorizontalAlignment(JTextField.RIGHT); content.add(textField); textField = new JTextField("Leading"); textField.setHorizontalAlignment(JTextField.LEADING); content.add(textField); textField = new JTextField("Trailing"); textField.setHorizontalAlignment(JTextField.TRAILING); content.add(textField); frame.pack(); frame.setSize(250, (int) frame.getSize().getHeight()); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(0, 1)); JTextField textField = new JTextField("Left"); textField.setHorizontalAlignment(JTextField.LEFT); frame.add(textField);/*from w w w .j ava2 s . c o m*/ textField = new JTextField("Center"); textField.setHorizontalAlignment(JTextField.CENTER); frame.add(textField); textField = new JTextField("Right"); textField.setHorizontalAlignment(JTextField.RIGHT); frame.add(textField); textField = new JTextField("Leading"); textField.setHorizontalAlignment(JTextField.LEADING); frame.add(textField); textField = new JTextField("Trailing"); textField.setHorizontalAlignment(JTextField.TRAILING); frame.add(textField); frame.pack(); frame.setSize(250, (int) frame.getSize().getHeight()); frame.setVisible(true); }
From source file:TextFieldExample.java
public static void main(String[] args) { try {//from w ww.j a va2s . c o m UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Text Field Examples"); f.getContentPane().setLayout(new FlowLayout()); f.getContentPane().add(new JTextField("Text field 1")); f.getContentPane().add(new JTextField("Text field 2", 8)); JTextField t = new JTextField("Text field 3", 8); t.setHorizontalAlignment(JTextField.RIGHT); f.getContentPane().add(t); t = new JTextField("Text field 4", 8); t.setHorizontalAlignment(JTextField.CENTER); f.getContentPane().add(t); f.getContentPane().add(new JTextField("Text field 5", 3)); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextField tf = new JTextField("press <enter>", 20); tf.setHorizontalAlignment(JTextField.RIGHT); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int old = tf.getHorizontalAlignment(); if (old == JTextField.LEFT) tf.setHorizontalAlignment(JTextField.RIGHT); if (old == JTextField.RIGHT) tf.setHorizontalAlignment(JTextField.CENTER); if (old == JTextField.CENTER) tf.setHorizontalAlignment(JTextField.LEFT); }//from w w w . ja v a 2 s. c o m }); JFrame frame = new JFrame("JTextFieldExample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new java.awt.FlowLayout()); frame.getContentPane().add(tf); frame.setSize(275, 75); frame.setVisible(true); tf.requestFocus(); }
From source file:Main.java
public static void main(String[] argv) { JTextField textfield = new JTextField("Initial Text"); // Left-justify the text textfield.setHorizontalAlignment(JTextField.LEFT); // Center the text textfield.setHorizontalAlignment(JTextField.CENTER); // Right-justify the text textfield.setHorizontalAlignment(JTextField.RIGHT); }
From source file:FocusTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); FocusListener listener = new FocusListener() { public void focusGained(FocusEvent e) { dumpInfo(e);//from w w w .j a v a 2s .c o m } public void focusLost(FocusEvent e) { dumpInfo(e); } private void dumpInfo(FocusEvent e) { System.out.println("Source : " + name(e.getComponent())); System.out.println("Opposite : " + name(e.getOppositeComponent())); System.out.println("Temporary: " + e.isTemporary()); } private String name(Component c) { return (c == null) ? null : c.getName(); } }; // First JPanel panel = new JPanel(); JLabel label = new JLabel("Label 1: "); JTextField text = new JTextField("Type your text", 15); text.setName("First"); text.addFocusListener(listener); label.setDisplayedMnemonic(KeyEvent.VK_1); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.NORTH); // Second panel = new JPanel(); label = new JLabel("Label 2: "); text = new JTextField("14.0", 10); text.setName("Second"); text.addFocusListener(listener); text.setHorizontalAlignment(JTextField.RIGHT); label.setDisplayedMnemonic(KeyEvent.VK_2); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.SOUTH); frame.pack(); frame.show(); }