File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Perhaps this time the fleet needs to sail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Perhaps this time the fleet needs to sail " Watch "Perhaps this time the fleet needs to sail " New topic
Author

Perhaps this time the fleet needs to sail

Chris Crawford
Ranch Hand

Joined: Jun 22, 2011
Posts: 87

Last night I solved my problem with a JLayeredPane merely by preparing the SSCCE (or whatever the acronym is). But this time I seem to be well and truly stuck. Here's the basic code, which does in fact compile and produce results that are not what I think they should be:



I have stripped out a bunch of radio buttons that accompanied godButton. I made the background of rightLowerPanel pink so that it would stand out against homeImage.

Some background information: homeImage.jpg fills mainFrame; rightLowerPanel contains JRadioButtons, but only one in this example. I tried three different variations of the layer depths of the two JComponents: (0,0); (0,1); and (1,0), just to make sure that I didn't have the layer depth interpretations backwards (The documentation describes two interpretations that are opposed to each other -- I'd love to hear how the Java designers got themselves into that mess!)

The results: homeImage shows up in all three combinations of depth settings; rightLowerPanel never shows up in any of the depth settings. My expectation is that rightLowerPanel should show up on top of homeImage.

My guess is that I am leaving out one of the myriad enabling settings. If this be so, then one of you folks will ask "Did you remember to use setFlopDoodle(true)?" and I'll answer "Oops! Sorry, I shoulda thought of that."

As always, thanks in advance for your help.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
It doesn't compile when I try to copy/paste/compile the code.
Chris Crawford
Ranch Hand

Joined: Jun 22, 2011
Posts: 87

Oops -- sorry, I forgot that you need all the core definitions. Here we go:



I hope this covers it for you. Thanks again.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2183
    
    7
A layered pane doesn't use a layout manager so you need to set the size/location of all components you add to the layered pane:



I included my version which helps with other little coding problems as well:

Chris Crawford
Ranch Hand

Joined: Jun 22, 2011
Posts: 87

Thank you, thank you, thank you! Your solution worked perfectly! I had been confused about whether to use a new JLayeredPane instead of the one belonging to mainFrame, but one of the topics I found here on a search for JLayeredPane used the latter approach, so I decided to go with that. And I've always been confused about the best time to include the mainFrame.setVisible(true) call; henceforth I'll always put it at the END of all the other setup code.

I must confess, I've never really "gotten the feel of" Swing. I've been using it in a putzy way for some years now, and most of the time my stuff works, but I seldom can figure out why when it doesn't work. I've read about its internal processes, but they're a bit too complicated for me to truly grasp.

Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Perhaps this time the fleet needs to sail