Re: Using two JFrames with one always mimicking the other



cokofreedom@xxxxxxxxx wrote:
On May 27, 2:27 pm, Andrew Thompson <andrewtho...@xxxxxxxxx> wrote:
On May 27, 10:01 pm, cokofree...@xxxxxxxxx wrote:
...

I have a Main Frame and a Log Frame.
Why? Or rather, why not put the relevant
components from both, into a single frame?

--
Andrew T.
PhySci.org

Well, I'm not exactly sure why...Because it seemed the easier method?
The idea is that the Log Frame will be receiving constant log
information from a wide selection of classes, but I would be wanting
to do constant actions in the Main Frame and so don't want it locking
up while it outputs the messages.
You're approach doesn't solve your goal! All parts of your code that interact with the GUI *must* do so on the Event Dispatch Thread. If your Log Frame is blocking the EDT, your Main Frame will be blocked anyway.

Andrew is right, it would be better to put them into the same frame. You might look into JDesktopPane and JInternalFrame if you want to keep the windows separate, but tied together.

As for the logging window itself, if you expect a large amount of "traffic", you might consider decoupling the "logging" aspect from the "rendering the log" aspect. Actually, you probably should do that anyway. For example, you should probably log to a buffer and/or file and/or database, and have the Log window read from that file/database/buffer every so often (using a Swing Timer). Half a second might be often enough, you can make it configurable by the user though. If that isn't frequent enough, then the chances are that more information is scrolling by than what a human can interpret anyway :-)

Hope this helps,
Daniel.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.


Quantcast