Java Swing How to - Create Right justified JTextfield








Question

We would like to know how to create Right justified JTextfield.

Answer

  /*from w ww  . ja v a  2 s.  c  o m*/


import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class Main{

  public static void main(String[] argv) {
    JTextField textfield = new JTextField(10);
    textfield.setHorizontalAlignment(JTextField.RIGHT);
    
    JOptionPane.showMessageDialog(null, textfield);
  }
}