Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2008

Tip: Looking for answers? Try searching our database.

Using two JFrames with one always mimicking the other

Thread view: 
cokofreedom@gmail.com - 27 May 2008 13:01 GMT
Hi,

I have a Main Frame and a Log Frame. I currently have it so that when
I move my Main Frame the Log Frame follows it, and when I minimize and
maximize my Main Frame the Log Frame does the same action.

But I cannot work out how to get the Log Frame to gain focus when I
have a separate window (say my IDE) open and then click on the Main
Frame. The Log Frame will not appear because I have no minimized or
maximized my Main Frame. (It will still follow it correctly so when I
personally click on its Window Icon it is below my Main Frame).

I was wondering whether I had just missed a simple ActionControl call
to enable my Log Frame to gain Focus at the same time as my Main
Frame.

windowGainedFocus and focusGained seemed to the obvious two events to
use from my Main Frame, but I cannot see how to make my Log Frame gain
focus as well.

Any help will be welcomed!

Coko
Andrew Thompson - 27 May 2008 13:27 GMT
On May 27, 10:01 pm, cokofree...@gmail.com 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
cokofreedom@gmail.com - 27 May 2008 13:36 GMT
> On May 27, 10:01 pm, cokofree...@gmail.com wrote:
> ...
[quoted text clipped - 7 lines]
> 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.
Andrew Thompson - 27 May 2008 14:06 GMT
On May 27, 10:36 pm, cokofree...@gmail.com wrote:

> > On May 27, 10:01 pm, cokofree...@gmail.com wrote:
> > ...
[quoted text clipped - 3 lines]
> > Why?  Or rather, why not put the relevant
> > components from both, into a single frame?

(Please trim sigs from replies.)

> Well, I'm not exactly sure why...Because it seemed the easier method?

Uh-huhh.  It seems, even from your question, that
this approach might have it's pitfalls.

> 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.

Multi-threading should solve that (and is
the best solution to it).

As far as putting all the components into a
single frame, you might look to using a JSplitPane,
which can be anything from 'half and half' of the
content area devoted to the groups of components,
or the user (or application) reassigning space to
one or the other as needs dictate.

OTOH there are a number of other possible layouts
that might better suit these collection of
components.

But I suggest you abandon the 'twin frames'
approach, it seems like a non optimal strategy,
to me.

--
Andrew T.
PhySci.org
Daniel Pitts - 27 May 2008 16:24 GMT
>> On May 27, 10:01 pm, cokofree...@gmail.com wrote:
>> ...
[quoted text clipped - 12 lines]
> 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.

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.