Set JTextField text center

Source code below will show you, how to make text in JTextField start at center.

************************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldTextToCenter.java
************************************************************************


import javax.swing.JTextField;
import javax.swing.JFrame;

import javax.swing.SwingConstants;

public class SetJTextFieldTextToCenter
{
public static void main(String[]args)
{
JTextField textField=new JTextField(10);

//Make text in JTextField start at center
textField.setHorizontalAlignment(SwingConstants.CENTER);

JFrame frame=new JFrame("Set JTextField text to center");
frame.add(textField);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,65);
frame.setVisible(true);
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************

RELAXING NATURE VIDEO