JTextField Horizontal Alignment - Java Swing

Java examples for Swing:JTextField

Description

JTextField Horizontal Alignment

Demo Code

 
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;
                }
        }
}

Related Tutorials