Java examples for Swing:JTextField
Aligning the Text in a JTextField Component
import javax.swing.JTextField; public class Main { public static void main(String[] args) { // 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); }/*from w w w . j a v a2 s .co m*/ }