Java examples for Swing:JTextField
JTextField Horizontal Alignment
import java.awt.FlowLayout; import javax.swing.JApplet; import javax.swing.JTextField; public class Main { public void init(){ JTextField field = new JTextField("JTextField Horizontal Alignment Example", 10); int horizontalAlignment = field.getHorizontalAlignment(); /*from w w w .j av a 2s . c o m*/ switch(horizontalAlignment){ case JTextField.LEFT: field.setText("Left"); break; case JTextField.RIGHT: field.setText("Right"); break; case JTextField.CENTER: field.setText("Center"); break; case JTextField.LEADING: field.setText("Leading"); break; case JTextField.TRAILING: field.setText("Trailing"); break; } } }