Search code examples
javajtextfield

How to center integer values in JTextFields?


x = new JTextField("");

count1 =22; 
String s1 = new Integer(count1).toString();
x.setText(s1); 

How can I make the entry in the JTextfield x to be in the center. I know i can do something like

x.setText(" " +s1+ " ");

But I want the Jtextfield only contain "integer" value for a purpose. So is there a way I can do something like ?

x.setText(s1, JTextField.Center);


Solution

  • x.setHorizontalAlignment(x.CENTER);