• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to close the previous JWindow

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic