Java JPasswordField request focus

Description

Java JPasswordField request focus

import java.awt.FlowLayout;

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

class Demo extends JPanel {
  public Demo() {    
    setLayout(new FlowLayout());
    //from   www.j av  a2  s  .com
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setActionCommand("password");
    
    passwordField.requestFocusInWindow();

    add(passwordField);
  }
}

public class Main {
  public static void main(String[] args) {
    Demo panel = new Demo();
    JFrame application = new JFrame();
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    application.add(panel);
    application.setSize(250, 250);
    application.setVisible(true);
  }
}



PreviousNext

Related