The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.text  [49 examples] > JTextField  [3 examples]

e981. Aligning the Text in a JTextField Component

    // Create a text field with some initial text
    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);

 Related Examples
e979. Creating a JTextField Component
e980. Creating a Password JTextField Component

See also: Actions and Key Bindings    Caret and Selection    Events    JEditorPane    JFormattedTextField    JTextArea    JTextComponent    JTextPane    Styles   


© 2002 Addison-Wesley.