wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JFileChooser showing twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFileChooser showing twice" Watch "JFileChooser showing twice" New topic
Author

JFileChooser showing twice

Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
I've got an aplication with a JPanel in it, and I also have outside this panel a JFileChooser, when I click a button on the JPanel I call the JFileChooser, but after I click "OK" it appears again, why? my code for opening the JFileChooser is this:

Contenido is my JPanel
The JFileChooser code is this:


Thanks
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Because you added it to the JPanel. Don't add it to the JPanel, when you show an open dialog it will pop up in it's own frame, it shouldn't be added to anything.
Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
If I don't add it I get this:

and a lot more of stuff...
the line giving the problem is this:


And if I add it, it works, any clue why this is happening???

Ok, I've done a little mor of investinagtion, and I've found that it opens twice becaus it enters twices to de case "add" on the actionPerformed function I've got for doing actions when menu options are pressed. I don't know what's happening, it only enters once to the other opciotns.
[ November 17, 2005: Message edited by: Emili Calonge ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38020
    
  22
I have never tried this before, but you appear to be opening the JFileChooser in front of itself.
When you write showAnythingDialog(this.BuscadorFicheros), then the AnythingDialog opens infront of BuscadorFicheros.
BUT BuscadorFicheros isn't there for it to open in front of.
Try putting a different component as the argument for showOpenDialog, and see whether that helps.
CR
Emili Calonge
Ranch Hand

Joined: May 17, 2003
Posts: 84
I've tried, this.Buscador_Ficheros, null, this, but the same thing happens, it opens twice, I really think the problem comes form the menu selection calling actionPrformed twice, but I don't now wahy this would happen, in the other menu options it only calls actionperformed once, I'm really confused, and I'm really stressed because I need this by tomorrow...
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
Try replacing

with


So the JFileChoser will be created but not added to JPanel.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFileChooser showing twice
 
Similar Threads
JFileChooser in an applet
Using a FileChooser to get and display an image
JFileChooser: Selecting multiple files error
JFileChooser to save file
HELP! me pls i can't open image on JLabel