Re: How to change JPanels?
On 16/02/11 16:42, Eric wrote:
On Feb 16, 9:26 am, Lew <no...@lewscanon.com> wrote:
To summarize. There is one EDT. Swing handles that threading automatically.
You have to give it GUI commands to handle, otherwise they simply cannot run
on the EDT. You are the programmer. You put the calls on the EDT, using
'invokeLater()' and its sister. The EDT is a single thread and there's only
one of it. If you run slow things on the EDT, you will have a slow GUI. That
is bad. Run slow things off the GUI. Run GUI things on the GUI. It's up to
you do to that.
--
Lew
Don't quote sigs.
From the Oracle docs:
public static boolean isEventDispatchThread()
Returns true if the current thread is an AWT event dispatching thread.
This is where you're confusing. You're saying there's one EDT.
Oracle says there's more.
Over the entire planet, there are.
It does not say *the* EDT, it says *an* EDT.
As you said before, semantics. There can never be more than one thread
controlling the GUI. If there were, anarchy would ensue. Just like
happens if you attempt to modify the GUI from any other thread.
So this is what that really means:
Windows has a single event queue, which communicates between
programmer and user. The programmer can tell the queue to show the
user a new window, a new button on the window, and a menu option on
the window. Those things can happen in different orders. The window
must be created first. The button may be added before or after the
menu option. Those controls may be added from different threads,
multiple EDTs interacting with the one event queue.
No, no, no. Absolutely not. Take a 1000 lines - "There is one, and only
one, EDT."
Components may only safely be added, or modified, by the EDT. Any other
thread must request that the EDT do it for them. The "single event
queue", as you put it, is part of Swing and is run by the EDT.
--
Nigel Wade