Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser showing twice

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try replacing

with


So the JFileChoser will be created but not added to JPanel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic