tag:blogger.com,1999:blog-4222197394079314848.post7582285698955770361..comments2023-05-10T02:34:45.071-05:00Comments on Mark A. Ziesemer: Java password dialogMark A. Ziesemerhttp://www.blogger.com/profile/12752422620777325409noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-4222197394079314848.post-51401729973526843652011-01-12T17:34:50.370-06:002011-01-12T17:34:50.370-06:00Reading all comments it occurs to me that trying t...Reading all comments it occurs to me that trying to use a buggy dialog and fighting to overcome it is complicated, unnatural, and useless because one never knows if it works on all platforms.<br /><br />The true solution, of course, would be that Sun people provide a JOptionPane.showPasswordDialog that would do exactly what an InputDialog does with a JPasswordField instead of a JTextField.<br /><Olivier Bertrandnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-26072637495464528952009-10-28T07:54:10.280-05:002009-10-28T07:54:10.280-05:00All - see the new alternative workaround recently ...All - see the new alternative workaround recently posted by Sun in the evaluation section of the reported bug, <a href="http://bugs.sun.com./bugdatabase/view_bug.do?bug_id=5018574" rel="nofollow">5018574</a>. I've not tested it yet, but it uses a HierarchyListener instead.Mark A. Ziesemerhttps://www.blogger.com/profile/12752422620777325409noreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-90672751869664176652009-10-28T04:13:16.575-05:002009-10-28T04:13:16.575-05:00jop.getValue() returns null as soon as the dialog ...jop.getValue() returns null as soon as the dialog is closed with Alt+F4.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-61765377539690479702009-10-28T03:38:33.269-05:002009-10-28T03:38:33.269-05:00windowOpened worked for me under Vista.
dialog.ad...windowOpened worked for me under Vista.<br /><br />dialog.addWindowListener(new WindowAdapter()<br /> {<br /> public void windowOpened(WindowEvent e)<br /> {<br /> jpf.requestFocusInWindow();<br /> }<br /> });<br /><br />My problem is that when I close the dialog using Alt+F4, my app goes to lala land since its still waiting for me to press OK/Cancel on a dialog that's alreadyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-13932958732020537462009-08-24T08:31:27.154-05:002009-08-24T08:31:27.154-05:00The solution using windowGainedFocus almost worked...The solution using windowGainedFocus almost worked. I could _see_ the password field having focus before it was moved to the OK button again. I came up with this and it works (at least on my Ubuntu machine running Sun JVM):<br /><br />wrapper.addWindowListener(new java.awt.event.WindowAdapter(){<br /> @Override<br /> public void windowGainedFocus(java.awt.event.WindowEvent e){<br />Akerboshttp://senke.verrech.netnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-68963379486626626412009-06-04T15:29:00.943-05:002009-06-04T15:29:00.943-05:00I came up with this approach also, but I used a Wi...I came up with this approach also, but I used a WindowFocusListener (the windowGainedFocus) event, so that when the window gets the focus then the password field requests the focus within the window.<br /><br />I haven't tested this on my platforms yet to see if it always works (I didn't realize it was an issue until I read this post just now), but it's something to try.<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-68164705817042803582009-06-02T06:49:43.051-05:002009-06-02T06:49:43.051-05:00Hi Mark.
It seems the ComponentListener is not th...Hi Mark.<br /><br />It seems the ComponentListener is not the best choice, as it can be system-dependant in what order the components are painted, and therefor it is called to early. (at elast on my Vista platform)<br /><br />If you use a WindowListener instead, it worked fine on all my platforms, since the Window seems usually activated when it is painted completely.<br /><br />Not sure if it Thomasnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-10428758120677363482009-05-26T21:26:25.795-05:002009-05-26T21:26:25.795-05:00Adam - I had never tested this under Linux until n...Adam - I had never tested this under Linux until now, and was able to confirm your issue. What I did notice is that requestFocusInWindow() returns a boolean giving an indication to the success. Under Linux, it was returning false, meaning "the focus change request is guaranteed to fail".<br /><br />I just updated the example in the post to include the call to requestFocusInWindow() toMark A. Ziesemerhttps://www.blogger.com/profile/12752422620777325409noreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-13419612313926802952009-05-26T20:22:23.810-05:002009-05-26T20:22:23.810-05:00I like this solution the most of everything that's...I like this solution the most of everything that's been offered up online, but I haven't been able to get this (or the AncestorListener trick) to work using jdk 1.6.0_13 on linux.<br /><br />Has anyone else had success with these hacks in later releases of Swing?Adamnoreply@blogger.comtag:blogger.com,1999:blog-4222197394079314848.post-46501979875966533502009-01-06T03:48:00.000-06:002009-01-06T03:48:00.000-06:00Very handy. Thanks! I've just added it to my Remot...Very handy. Thanks! I've just added it to my RemoteLoginAction module, with attribution of course.<BR/>http://agilewiki.wiki.sourceforge.net/Bill la Forgehttps://www.blogger.com/profile/11660659618343045817noreply@blogger.com