2

Everytime I open a JFrame from my main JFrame It appears in front of my main JFrame. I know how to open it in different positions of the screen but that doesn't solve the problem.

I have no idea how to open it behind the main JFrame. Any help would be appreciated.

ashiquzzaman33
  • 5,781
  • 5
  • 31
  • 42
manelmc
  • 937
  • 2
  • 7
  • 17
  • 1
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) *"I have no idea how to open it behind the main JFrame."* I don't see that as a bad thing, given it would be confusing to the end user. – Andrew Thompson Sep 21 '15 at 20:39
  • @AndrewThompson Thanks for the advice. – manelmc Sep 21 '15 at 21:52

1 Answers1

4

You can use toBack() method after setVisible(true) method to open New JFrame behind the main JFrame.

Example code:

newFrame.setVisible(true);
newFrame.toBack();
ashiquzzaman33
  • 5,781
  • 5
  • 31
  • 42
  • It would need to be tested, but under some os's, this might not work – MadProgrammer Sep 21 '15 at 21:21
  • @MadProgrammer Tested with windows 10 and windows 8 but as javadoc says it might not work on all platform. – ashiquzzaman33 Sep 21 '15 at 21:26
  • 1
    I think it's the right approach (or the best we have available, just need to beware ;)) – MadProgrammer Sep 21 '15 at 21:39
  • It works on windows 7 but It doesn't have the desired effect, surrounding the JFrame opening block with `setAlwaysOnTop(true)` and `setAlwaysOnTop(false)` It was the best option. Even though It's quite bungler. – manelmc Sep 21 '15 at 21:49
  • @YassinHH because I thought that might suit better with the next person looking for the question I made. Still thank you very much. – manelmc Sep 22 '15 at 16:03