• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JFrame in a JFrame?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible for a JFrame to contain another JFrame? This is a question posed by the the following post from 2008.

https://coderanch.com/t/346079/Swing-AWT-SWT-JFace/java/JFrame

I have created a simple stand alone JFrame-based graphical application that needs to be the background for various other frames/dialogs. I tested my stand alone with JInternalFrames, and it worked just the way I wanted. However, when I went to integrate with a larger app (which is it's intended purpose), I discovered that app was JFrame-based as well. Looking through that code, it seems very problematic to try and change it to JInternalFrame. In addition, the main project also launches various JDialog based windows as part of it's normal operation.

The entire purpose of my app when bundled with the main app is to act as a background or container for that app. Specifically, I have two requirements:

1) My JFrame needs to always be on the bottom, behind all other frames/dialogs.
2) My JFrame needs to be the bounding area of all the other frames/dialogs.

Working with JInternalFrames, this comes naturally. But as it stands now, the best I can do is instantiate my app, then the main app as well. And that main app is in no way bounded to or by my JFrame. Does anybody know a way around this? I'm trying to alter the main apps code as littel as possible and do all the work or fancy stuff in my code. I would appreciate any advice that anybody has to send my way. Here is an tiny example of what I'm trying to do, that is failing.



Thanks again, and any alternative approaches are, of course, welcome.
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you haven't already, have a look at The JInternalFrame class, JInternalFrame can exist inside of a JFrame.

edit, OK I sshould have looked closer at your post first, I see you know about JInternalFrame already . Sorry
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A frame is represented by the components added to it. So you do something like:

somePanel.add( frame.getContentPane() );

or maybe

somePanel.add( frame.getRootPane() );
 
Art Vandalay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob and Fred, thanks for the timely responses. Rob, I tried your idea. It does part of the job. Basically, I see it takes the contents of JFrame2 and dumps them statically into JFrame1. Perhaps... no I'm certain... I did not explain the problem properly. So to add to my previous problem statement and hopefully succinctly summarize, I'm basically looking to have a JFrame, and various JDialogs owned, or contained within a "master" JFrame, with the same type of relationship that a JInternalFrame has to a JFrame. In other words, I wish to have the JFrame and JDialogs remain looking like a Dialog, with all the associated title bars, etc. However, they will be constrained (location wise) by the "parent" JFrame. Really, if I could figure out a way to restrict their movement so they couldn't be dragged outside the area of the master JFrame (which would be always placed in back), that would be an adequate solution. Because that gives the impression that the master JFrame is the "container" whether it really is or not. Hope I'm doing a decent job describing the issue.

Regards.

 
Art Vandalay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to hack away at the existing code very minimally, and change the JFrame to JInternalFrame. Now it behaves mostly as I'd like. However it does create several JDialogs and are not playing nicely (they're not constrained to within the JFrame). Any ideas?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i ran into the same problem making a game of battleship for a final project in class, and decided near the end that it would look cool to add pictures of the ships where they were placed, rather than just gray squares. needless to say after a few thousand lines of code without ever thinking about adding images, it was difficult to shoe-horn them in. and once i did they would disappear behind the main game board's frame when you clicked it to add another ship.

i found a great answer while searching google.

frame.setFocusableWindowState(false);

that one line of code did exactly what i wanted, making my main game board always in the background no matter what i added. very easy, very quick.

also, sorry for bumping an old post
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic