I have a class that extends javax.swing.JFrame built with NetBeans GUI editor. Is there a way to make this JFrame cascade when several of it being opened ?
Asked
Active
Viewed 1,796 times
6
-
Unless you spawn the multiple frames from within the same program you may need to look into process id's or window titles which may involve native libraries. – rtheunissen Aug 27 '12 at 15:10
-
@Onca Are you opening the different frames from the same JVM or one at a time? – aymeric Aug 27 '12 at 15:32
-
From the same JVM, all together. – Onca Aug 27 '12 at 16:04
-
Since it seems you have not only chosen an answer that breaks from the X-plat behavior, and only works for a single JVM, I will add.. See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Aug 28 '12 at 00:44
3 Answers
5

Community
- 1
- 1

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
Note this method should work the same irrespective of same/different JVM. – Andrew Thompson Aug 27 '12 at 15:39
2
Just keep a variable with the previous such opened JFrame
location and for the next one do:
newFrame.setLocation(previousLocation.x + constant, previoudLocation.y + constant);
The getLocation()
will return you the location on screen of an existing JFrame
.

Dan D.
- 32,246
- 5
- 63
- 79
-
OP may have meant multiple instances of the application, ie. not from within the same JVM. – rtheunissen Aug 27 '12 at 15:11
2
JFrame
s are top-level components, they don't nest.
If you need nested frames (i.e. frames that can be a child of another frame), use JInternalFrame instead.
If you need to create new frames in the existing application when it is invoked again, use a Socket to send the arguments for the new frame from the new application to the existing one and then exit the new application.

Aaron Digulla
- 321,842
- 108
- 597
- 820
-
1Re. last paragraph. If the app. is launched using JWS it could use the `SingleInstanceService` as seen in [this demo.](http://pscode.org/jws/api.html#sis). – Andrew Thompson Aug 27 '12 at 15:38