• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFileChooser keeps coming up after I selected the file.  RSS feed

 
Mark Andy
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So there are two different classes TextFile and Project02. Project02 is GUI which I try and hit open file. It opens JFileChooser and I select a file and hit open then right away just opens the JFileChooser again.. I just need some pointers on where to fix this issue. I believe it would be in the "IF-ELSE" but I'm trying to maintain the same structure as this is for school.




 
Paul Clapham
Sheriff
Posts: 22813
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yeah, you're calling a method which uses a JFileChooser inside your panel's paint() method. That method can be called whenever the Swing code needs to call it. For example if you minimize your application and then restore it, the paint() method is going to be called to redisplay the panel. If you drag another application over that panel, its paint() method may be called more than once. So you shouldn't have that kind of code there. You'll need to move it to a place where you control where it gets called.
 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should not be code in a paint method to do things other than the painting. For example there should not be a call to the openFile method.
 
Mark Andy
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, I knew it had to be simple, Very new with GUI so I appreciate your explanation with that!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!