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.
A frame is represented by the components added to it. So you do something like:
somePanel.add( frame.getContentPane() );
somePanel.add( frame.getRootPane() );
posted 10 years ago
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.
posted 10 years ago
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?
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.
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
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?