Pages

Set JPasswordField text center

Complete source code below will show you, how to make text in JPasswordField start at center.

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


import javax.swing.JPasswordField;
import javax.swing.JFrame;

import javax.swing.SwingConstants;

public class SetJPasswordFieldContentsToCenter
{
public static void main(String[]args)
{
JPasswordField passwordField=new JPasswordField(10);

//Make contents in JPasswordField start at center
passwordField.setHorizontalAlignment(SwingConstants.CENTER);

JFrame frame=new JFrame("Set JPasswordField contents to center");
frame.add(passwordField);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,65);
frame.setVisible(true);
}
}


****************************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************************
Related Posts Plugin for WordPress, Blogger...