0

I have a frame with some components and a menu. Certain buttons on the frame and in the menu open a JFileChooser (a new instance each time) to open and save files.

My problem is simple, whenever I open a JFileChooser in Java and press OK, the menu is hidden behind the other controls in the frame. This means that when I open the menu, some menu items cannot be displayed.

However, if I don't press OK in the JFileChooser but press cancel, this doens't happen. I assume there is some error in how the frame is repainted after the FileChooser get an "OK". As I said, the stacking of components seems to be faulty.

I didn't mix Swing and AWT components by the way. All my components are Swing components.

EDIT: Here is my code

final JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(Books.getDirectory()));
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(new XmlFilter());
int returnVal = fileChooser.showOpenDialog(Main.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
// OK was pressed
}

Any ideas?

sanjon
  • 1
  • 2
  • Do you set proper parent component to the JFileChooser ? – StanislavL Oct 17 '13 at 09:54
  • 4
    Code? Screenshots? Might make easier for us to see what is happening! – Java Devil Oct 17 '13 at 10:04
  • For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Oct 18 '13 at 01:06
  • @java-devil OK, I added the code I have right now. I can't access the instance of the frame as with the 'this' keyword because it's inside an actionPerformed() event handler. That's why I'm using Main.this. – sanjon Oct 18 '13 at 13:07
  • Have `actionPerformed` call another method outside of the `ActionListener` so you can properly access the frame with `this`. This still doesn't show us what you mean by menu is hidden behind? And also if it was anything its the code within your condition which is causing the problem. – Java Devil Oct 19 '13 at 03:23

0 Answers0