<Swing Dev> <AWT Dev> Code review request: 7025699: Policy Tool is not accessible by keyboard

Anthony Petrov anthony.petrov at oracle.com
Tue Oct 15 16:43:29 UTC 2013


Well, performing I/O or other blocking operations on EDT can only freeze 
the app's GUI for the period of blocking. If developers/users are OK 
with that, this is fine with me too.

However, you should still call all Swing APIs (including creating your 
components/windows) on the EDT. And I don't see this is being done in 
your current code. As a minimum, the displayToolWindow() method should 
be dispatched on the event thread. I haven't examined the code closely, 
but if there are any other GUI updates from separate threads, those 
should also be moved to the EDT. See the following tutorial for details:

http://docs.oracle.com/javase/tutorial/uiswing/concurrency/dispatch.html

--
best regards,
Anthony

On 10/15/2013 06:13 PM, Weijun Wang wrote:
> Policy Tool is a GUI editor for the plain text policy file. The only I/O
> is loading the policy file from disk and it should be quite small, so I
> think there won't be a problem here.
>
> Thanks
> Max
>
> On 10/15/13 8:08 PM, Anthony Petrov wrote:
>> Hi Max,
>>
>> I don't have expertise in this code so I haven't reviewed the fix
>> thoroughly. I'd like to point out one thing though: unlike AWT, Swing is
>> a single-threaded GUI toolkit. While in AWT you can create
>> components/windows and call APIs on any thread, in Swing everything
>> GUI-related must be performed on the Event Dispatch Thread (EDT) only.
>> Any long, non-GUI-related operations (like I/O, computations, etc.)
>> should be dispatched on other threads (with a SwingWorker, for example).
>>
>> I don't see a single SwingUtilities.invokeLater/invokeAndWait() call in
>> PolicyTool.java, so I thought I'd ask whether you're aware of the
>> threading limitations imposed by Swing and how those are going to be
>> addressed?
>>
>> --
>> best regards,
>> Anthony
>>
>> On 10/12/2013 04:49 AM, Weijun Wang wrote:
>>> Hi All
>>>
>>> Please review the fix at
>>>
>>>     http://cr.openjdk.java.net/~weijun/7025699/webrev.00/
>>>
>>> The fix includes porting PolicyTool from AWT to Swing, defining
>>> mnemonics for menu items and buttons, and adding keyboard shortcuts for
>>> the File -> New/Open/Save items. Several tests are updated also.
>>>
>>> Thanks
>>> Max



More information about the swing-dev mailing list