JOptionPane to get password

后端 未结 6 993
耶瑟儿~
耶瑟儿~ 2020-12-01 13:52

JOptionPane can be used to get string inputs from user, but in my case, I want to display a password field in showInputDialog.

The way I ne

6条回答
  •  一个人的身影
    2020-12-01 14:26

    This dialogue looks a lot better if you do

    dlg.setVisible(true);
    

    Without that you can't see it at all.

    Also

    pPnl.gainedFocus();
    

    should be

    pPnl.gainedFocus();
    

    Other than that it works great. Thanks for the code. Saved me time facing around with Swing.

    Also, if you don't want to leave the dialogue running in the background every time you open it, you'll need to close it with something like

    dlg.dispatchEvent(new WindowEvent(dlg, WindowEvent.WINDOW_CLOSING));
    dlg.dispose(); // else java VM will wait for dialog to be disposed of (forever)
    

提交回复
热议问题