Java tutorial
//package com.java2s; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPasswordField; public class Main { public static JPasswordField addLabeledPwdField(JComponent c, String label, int length, boolean wrap) { JLabel l = new JLabel(label); c.add(l, "align left"); JPasswordField pwd = new JPasswordField(length); if (wrap) { c.add(pwd, "align left, wrap"); } else { c.add(pwd, "align left"); } return pwd; } }