File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to close the previous JWindow

 
Kee Kee moon
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Users click on a button opening more than one JWindow. User can only close the latest JWindow, but not the previous one.
How to close the previous JWindows?

Thanks
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe it's something to do with JWindow. with JFrame there is no problem. close the second one then use or close the first.
 
Rob Spoor
Sheriff
Pie
Posts: 20371
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you even trying to close the JWindows? They don't have a close button by default. They also don't show up in the task bar. That means you must have added something for closing them.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most probably you have one instance reference to the JWindow and everytime a new window is created you are doing something like myJWindow=new JWindow(); Then later on somewhere you are calling myJWindow#setVisible(false) resulting in only the latest one being closed. Of course I am just shooting in the dark here. Like Rob said, you need to tell us more.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Most probably you have one instance reference to the JWindow and everytime a new window is created you are doing something like myJWindow=new JWindow(); Then later on somewhere you are calling myJWindow#setVisible(false) resulting in only the latest one being closed. Of course I am just shooting in the dark here. Like Rob said, you need to tell us more.



I use JWindow to display images. Please see below that is how I open a JWindow. Each time I click on a small image, it
will open an JWindow to enlarge the small image. If I keep click on images without closing (dispose()) the current JWindow,
the program will open more than one JWindow. If I have multiple JWindow are opened, I can only close the latest one I open.
How to close( dispose()) all of JWindow ???


JWindow window = new JWindow() to open a new JWindow.
dispose() to close JWindow.



 
Rob Spoor
Sheriff
Pie
Posts: 20371
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to keep track of the windows. You can use Window.getWindows(), but I'd prefer my own List<JWindow> for this.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:You will need to keep track of the windows. You can use Window.getWindows(), but I'd prefer my own List<JWindow> for this.


Thank you Bob.

This is what I did, please see below and It works. Thank you again Bob.

Window[] windows = window.getWindows();
for (Window win : windows) {
if (!win.getName().startsWith("frame")) { // I don't want to close the JFrame, but JWindow only
win.dispose();
}
}
 
Rob Spoor
Sheriff
Pie
Posts: 20371
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's Rob, not Bob. Also, your code may also close any dialog that is shown. A check against the type (if (window instanceof JWindow) is somewhat safer.
 
Kee Kee moon
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:It's Rob, not Bob. Also, your code may also close any dialog that is shown. A check against the type (if (window instanceof JWindow) is somewhat safer.


I am sorry about your name. I should have changed the font to be bigger, so I can read the web easier.
And, thank for your help again about Dialog window.
 
Rob Spoor
Sheriff
Pie
Posts: 20371
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic