I don't know what's wrong with my code but the password does not turn into dots. Please help me. >.<
Here is my UI code:
private final JPanel contentPanel = new JPanel();
public JPasswordField password_id;
public JFormattedTextField user_ID;
public JButton btnAccept;
private JFormattedTextField previouslyFocusedTextBox = user_ID;
public login(final JFrame parent, boolean modal) {
super(parent, modal);
setBounds(100, 100, 469, 428);
getContentPane().setLayout(new BorderLayout());
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Dimension screenSize = toolkit.getScreenSize();
final int x = (screenSize.width - getWidth()) / 2;
final int y = (screenSize.height - getHeight()) / 2;
setLocation(x, y);
setResizable(false);
FlowLayout flow_2 = new FlowLayout(0,0,0);
final JPanel panel_1 = new JPanel();
panel_1.setBackground(new Color(128, 0, 128));
panel_1.setPreferredSize(new Dimension(10, 90));
panel_1.setBounds(new Rectangle(0, 0, 100, 100));
panel_1.setBorder(new EmptyBorder(50, 90, 0, 0));
panel_1.setLayout(flow_2);
header_Login.add(panel_1, BorderLayout.SOUTH);
user_ID = new JFormattedTextField();
user_ID.setFocusTraversalKeysEnabled(true);
user_ID.setFocusable(true);
user_ID.addFocusListener(this);
user_ID.setBounds(0, 0, 423, 45);
panel_1.add(user_ID);
user_ID.setMinimumSize(new Dimension(8, 32));
user_ID.setUI(new JTextFieldHintUI("Enter ID Here", Color.gray));
user_ID.setHorizontalAlignment(SwingConstants.LEFT);
user_ID.setFont(new Font("Calibri", Font.BOLD, 35));
user_ID.setPreferredSize( new Dimension(10, 40) );
user_ID.setColumns(20);
FlowLayout flow_3 = new FlowLayout(0,0,0);
JPanel body_Login = new JPanel();
body_Login.setBackground(new Color(128, 0, 128));
body_Login.setBorder(new EmptyBorder(0, 0, 0, 0));
getContentPane().add(body_Login, BorderLayout.CENTER);
body_Login.setLayout(flow_3);
password_id = new JPasswordField ();
password_id.setFocusTraversalKeysEnabled(true);
password_id.setFocusable(true);
password_id.addFocusListener(this);
body_Login.add(password_id);
password_id.setMinimumSize(new Dimension(8, 32));
password_id.setUI(new JTextFieldHintUI("Enter PASSWORD Here", Color.gray));
password_id.setHorizontalAlignment(SwingConstants.LEFT);
password_id.setFont(new Font("Calibri", Font.BOLD, 35));
password_id.setPreferredSize( new Dimension(100, 40) );
password_id.setColumns(20);
And at the end of the code I got this:
public void focusGained(FocusEvent ev) {
//System.out.println("CHANGE");
if(ev.getSource() instanceof JFormattedTextField) {
previouslyFocusedTextBox = (JFormattedTextField) ev.getSource();
}
}
public void focusLost(FocusEvent arg0) {
// TODO Auto-generated method stub
}
I know its a bit messy and I'm still new in programming the UI manually so that's why I don't know my way around. Anyway, my JPasswordField is does not turn the text into dots. I already made it work a while ago but I revert it back again thinking it wasn't working. Anyway, I can't make it work again and I really don't know what I will do to make it work. The original code for the password is:
public JFormattedTextField password_id;
password_id = new JFormattedTextField((Format) null);
When I changed my code into JPasswordField the field does not focus on the password field maybe because of the FormattedTextField in previouslyFocusedTextBox. I really don't know what I should do to make the JPasswordField to make work. This project was not really made by me that's why I don't understand some of its uses. Please help me out.