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 / February 2005

Tip: Looking for answers? Try searching our database.

Focus to Owner JFrame?

Thread view: 
Dado - 09 Feb 2005 20:11 GMT
My main JFrame creates a second JFrame (second and it creates another
JFrame(third).
I want to, when click  the button on a 'third' frame, 'cascade' the other
two frames one in a front the other.
I mean: how to show the parent frame?
Alex Molochnikov - 10 Feb 2005 06:29 GMT
frame2.toFront();
frame1.toFront();

This, of course, assumes that the references to frames 1 and 2 are available
in the code that created frame 3.

> My main JFrame creates a second JFrame (second and it creates another
> JFrame(third).
> I want to, when click  the button on a 'third' frame, 'cascade' the other
> two frames one in a front the other.
> I mean: how to show the parent frame?
Dado - 10 Feb 2005 17:30 GMT
> frame2.toFront();
> frame1.toFront();
>
> This, of course, assumes that the references to frames 1 and 2 are
> available in the code that created frame 3.

And how to create references to parent frames?
If frames are created in this order:
frame1
   frame2
     frame3
 
Alex Molochnikov - 10 Feb 2005 21:29 GMT
JFrame frame1 = new JFrame("Title 1");
JFrame frame2 = new JFrame("Title 2");
.....

If frame2 is created in a different part of your program, pass the reference
either through the method call parameters, or instance variables (if the
frames are created within different methods of the same class), or
properties, etc.

Note that there is no such thing as a "parent" frame. Each JFrame is created
separately, and has life of its own. There is an "owner" window
(JFrame/Frame/JDialog/Dialog) that can be associated with a Dialog (or
JDialog), but there is no owner for a Frame/JFrame.

> And how to create references to parent frames?
>  If frames are created in this order:
> frame1
>     frame2
>       frame3
Dado - 11 Feb 2005 07:52 GMT
> JFrame frame1 = new JFrame("Title 1");
> JFrame frame2 = new JFrame("Title 2");
[quoted text clipped - 9 lines]
> (JFrame/Frame/JDialog/Dialog) that can be associated with a Dialog (or
> JDialog), but there is no owner for a Frame/JFrame.

OK. Thank you. I thougt that exist some more elegant solution but through
the methos called parameters, something like 'super' in a calling extended
class in a 'relations'between Frame->JFrame, for example.
Andrew Thompson - 11 Feb 2005 10:34 GMT
(Alex)
>> This, of course, assumes that the references to frames 1 and 2 are
>> available in the code that created frame 3.

That is not necessary.

> And how to create references to parent frames?
>  If frames are created in this order:
> frame1
>     frame2
>       frame3

This may help give you a start.

<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/** Uses the Frame.getFrames() method to find other Frames and
JFrames and bring them 'toFront'.  See getOwnedWindows()for
windows and dialogs. */
public class UpFront extends
 Frame implements ActionListener {

 static int number = 0;

 static final String NAME = "UpFront ";

 public UpFront() {
   super( NAME + number);
   setLayout( new GridLayout(0,1) );

   // assemble the UI
   Button b = new Button("All");
   b.addActionListener(this);

   // add a button for each known frame
   Frame[] allFrame = Frame.getFrames();
   add(b);
   for( int ii=0; ii<allFrame.length; ii++ ) {
     b = new Button( NAME + ii );
     b.addActionListener(this);
     add(b);
   }

   pack();
   setLocation( (getWidth()-5)*number++, 10 );
 }

 public void actionPerformed(ActionEvent ae) {
   String command = ae.getActionCommand();

   // a very handy static method of Frame
   Frame[] allFrame = Frame.getFrames();
   for( int ii=0; ii<allFrame.length; ii++ ) {
     String title = allFrame[ii].getTitle();
     if ( command.equals("All") ) {
       // bring all frames to front in turn
       allFrame[ii].toFront();
       System.out.println( title + ".toFront()" );
     } else {
       if ( command.equals( title ) ) {
         // bring only the named frame to front
         allFrame[ii].toFront();
         System.out.println( title + ".toFront()" );
       }
     }
   }
 }

 /** Accepts no arguments. */
 public static void main(String[] args) {
   for ( int ii=0; ii<5; ii++ ) {
     new UpFront().setVisible(true);
   }
   JFrame f = new JFrame("JFrame");
   f.getContentPane().add(
     new JLabel("This is a JFrame, rather than an 'UpFront'") );
   f.pack();
   f.setVisible(true);
 }
}
</sscce>

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



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.