JPanel panel = new JPanel(); JLabel label = new JLabel("Enter a password:"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[]{"OK", "Cancel"}; int option = JOptionPane.showOptionDialog(null, panel, "The title", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if(option == 0) // pressing OK button { char[] password = pass.getPassword(); System.out.println("Your password is: " + new String(password)); }
JTextField username = new JTextField(); JTextField password = new JPasswordField(); Object[] message = { "Username:", username, "Password:", password }; int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { if (username.getText().equals("h") && password.getText().equals("h")) { System.out.println("Login successful"); } else { System.out.println("login failed"); } } else { System.out.println("Login canceled"); }
JTextField firstName = new JTextField(); JTextField lastName = new JTextField(); JPasswordField password = new JPasswordField(); final JComponent[] inputs = new JComponent[] { new JLabel("First"), firstName, new JLabel("Last"), lastName, new JLabel("Password"), password }; int result = JOptionPane.showConfirmDialog(null, inputs, "My custom dialog", JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { System.out.println("You entered " + firstName.getText() + ", " + lastName.getText() + ", " + password.getText()); } else { System.out.println("User canceled / closed the dialog, result = " + result); }
String[] prompt, boolean[] echo) { panel = new JPanel(); panel.setLayout(new GridBagLayout()); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridx = 0; panel.add(new JLabel(instruction), gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 1; panel.add(new JLabel(prompt[i]), gbc); gbc.weighty = 1; if (echo[i]) { texts[i] = new JTextField(20); } else { texts[i] = new JPasswordField(20); panel.add(texts[i], gbc); gbc.gridy++;
/** * Prompt for a password, and wait until the user enters it. * @param prompt The prompt string * @return The new password. */ @SuppressWarnings("serial") private String getPassword(String prompt) { final JDialog input = new JDialog(mainWindow, "Prompt", true); input.setLayout(new FlowLayout()); input.add(new JLabel(prompt)); JPasswordField textField = new JPasswordField(10); input.add(textField); Action okAction = new AbstractAction("OK") { public void actionPerformed(ActionEvent e) { input.dispose(); } }; textField.addActionListener(okAction); JButton ok = new JButton(okAction); input.add(ok); input.pack(); input.setLocationRelativeTo(mainWindow); input.setVisible(true); // BLOCKING return new String(textField.getPassword()); }
public class TestPane extends JPanel { public TestPane() { Random rnd = new Random(); JPanel panel = new JPanel(); JPasswordField pf = new JPasswordField(10); JButton btn = new JButton("Login"); panel.add(pf); panel.add(btn); panel.setBorder(new EmptyBorder(rnd.nextInt(10), rnd.nextInt(10), rnd.nextInt(10), rnd.nextInt(10))); setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(rnd.nextInt(100), rnd.nextInt(100), rnd.nextInt(100), rnd.nextInt(100)); add(panel, gbc); } }
public class PasswordForm { private static String password = "mypass"; public static void main(String[] args){ //Swing operations should happen on the EDT EventQueue.invokeAndWait( new Runnable(){ public void run(){ //whole UI creation final JTextField usernameInput = new JTextField(10); final JPasswordField passwordInput = new JPasswordField(10); //more UI creation JButton loginInput = new JButton("Login"); loginInput.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(null,"Username is:" + usernameInput.getText() + " Password is:" + passwordInput.getText()); } }); } } //todo catch the exceptions from the invokeAndWait call } }
protected JPanel getKeystorePanel() { JPanel keyStorePanel = new JPanel(new GridLayout(4, 2)); keyStorePanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_DAVMAIL_SERVER_CERTIFICATE"))); keystoreTypeCombo = new JComboBox(new String[]{"JKS", "PKCS12"}); keystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.keystoreType")); keystoreFileField = new JTextField(Settings.getProperty("davmail.ssl.keystoreFile"), 20); keystorePassField = new JPasswordField(Settings.getProperty("davmail.ssl.keystorePass"), 20); keyPassField = new JPasswordField(Settings.getProperty("davmail.ssl.keyPass"), 20); addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_STORE_TYPE"), keystoreTypeCombo, BundleMessage.format("UI_KEY_STORE_TYPE_HELP")); addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_STORE"), keystoreFileField, BundleMessage.format("UI_KEY_STORE_HELP")); addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_STORE_PASSWORD"), keystorePassField, BundleMessage.format("UI_KEY_STORE_PASSWORD_HELP")); addSettingComponent(keyStorePanel, BundleMessage.format("UI_KEY_PASSWORD"), keyPassField, BundleMessage.format("UI_KEY_PASSWORD_HELP")); updateMaximumSize(keyStorePanel); return keyStorePanel; }
f.setLayout(new GridLayout(0, 1)); f.add(Laf.createToolBar(f)); f.add(new JTextField("bla@foo.com")); f.add(new JPasswordField("*****")); f.pack(); f.setLocationRelativeTo(null);
private final JPasswordField passwordField = new JPasswordField(12); private boolean gainedFocusBefore; super(new FlowLayout()); add(new JLabel("Password: ")); add(passwordField);
public class TestPane{ public static void main (String[] args) { Random rnd = new Random(); JFrame frame = new JFrame(); JPasswordField pf = new JPasswordField(); JButton btn = new JButton("Login"); frame.setSize(500, 500); frame.setLayout(null); btn.setBounds(y, x, width, height); pf.setBounds(y, x, width, height); frame.add(btn); frame.add(pf); } }
JLabel usrNameLabel = new JLabel("User Name"); changeCompFont(usrNameLabel); JTextField usrNameFeild = new JTextField("user name"); changeCompFont(usrNameFeild); usrNameLabel.setLabelFor(usrNameFeild); JLabel passwordLabel = new JLabel("Password"); changeCompFont(passwordLabel); JPasswordField passFeild = new JPasswordField("Password"); changeCompFont(passFeild); passFeild.setBorder(compundBorder); add(usrNameLabel, labCnst); add(usrNameFeild, txtCnst); add(passwordLabel, labCnst); add(passFeild, txtCnst);
JPanel panel = new JPanel(); JLabel label = new JLabel("Password:"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass);
lName = new javax.swing.JLabel(); lName1 = new javax.swing.JLabel(); tfUser = new javax.swing.JTextField(); passwordField = new javax.swing.JPasswordField();
/** * Prompt for a password, and wait until the user enters it. * @param prompt The prompt string * @return The new password. */ @SuppressWarnings("serial") private String getPassword(String prompt) { final JDialog input = new JDialog(mainWindow, "Prompt", true); input.setLayout(new FlowLayout()); input.add(new JLabel(prompt)); JPasswordField textField = new JPasswordField(10); input.add(textField); Action okAction = new AbstractAction("OK") { public void actionPerformed(ActionEvent e) { input.dispose(); } }; textField.addActionListener(okAction); JButton ok = new JButton(okAction); input.add(ok); input.pack(); input.setLocationRelativeTo(mainWindow); input.setVisible(true); // BLOCKING return new String(textField.getPassword()); }
JPanel panel = new JPanel(); JPasswordField pass = new JPasswordField(10) { public void addNotify() { panel.addNotify(); requestFocus(); } }; panel.add(pass); JOptionPane pane = new JOptionPane(); JButton btnOK = new JButton("OK"); JButton btnCancel = new JButton("Cancel"); Object[] options = {btnOK, btnCancel}; pane.showOptionDialog(null, panel, "Enter the password", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null);
userName = new JTextField(""); userName.setText("Username"); userName.setForeground(Color.GRAY); JPasswordField passWord = new JPasswordField(10); passWord.setEchoChar('*'); passWord.addActionListener(new AL()); b1 = new JButton("something"); getContentPane().add(b1);
tf = new JTextField("Cool Beans"); tf2 = new JTextField("UnCool Beans"); tf3 = new JTextField("Hot Beans"); pf = new JPasswordField("password");
JLabel label = new JLabel("Password") { @Override public Dimension getMaximumSize() { return super.getPreferredSize(); } }; JPasswordField field = new JPasswordField() { @Override public Dimension getMaximumSize() { return super.getPreferredSize(); } };
JLabel title = new JLabel(name); title.setForeground(Color.WHITE); title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>"); JPanel item = new JPanel(); item.setLayout(new BorderLayout()); item.setMinimumSize(new Dimension(PANEL_WIDTH, 0)); name = cid.getItem().name(); JLabel configEntryName = new JLabel(name); configEntryName.setForeground(Color.WHITE); configEntryName.setToolTipText("<html>" + name + ":<br>" + cid.getItem().description() + "</html>"); textField = new JPasswordField(); colorPickerBtn = new JButton("Pick a color"); colorPickerBtn = new JButton(ColorUtil.toHexColor(existingColor).toUpperCase()); JPanel dimensionPanel = new JPanel(); dimensionPanel.setLayout(new BorderLayout()); dimensionPanel.add(new JLabel(" x "), BorderLayout.CENTER); dimensionPanel.add(heightSpinner, BorderLayout.EAST); JButton resetButton = new JButton("Reset"); resetButton.addActionListener((e) ->