> 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