aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Difficulty with panel sizing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Difficulty with panel sizing" Watch "Difficulty with panel sizing" New topic

Difficulty with panel sizing

Rusty Swain

Joined: May 09, 2014
Posts: 2
I'm having trouble with this program. In my textbook it says "Write an application that displays a frame containing two panels. Each panel should contain two images (use four unique images - your choice). Fix the size of the first panel so that both of its images remain side by side. Allow the other panel to change size as needed. Experiment with the size of the window to see the images change orientation. Make sure you understand why the application behaves as it does". I successfully imported the images, but I can't find out anywhere how to allow the second panel to change size with the window. I'm sure I'm just missing something obvious, but I would really appreciate some help. I'm also not really sure how to put code in here the right way so I'm sorry if it looks weird.

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Hi Rusty, welcome to the Ranch!

Does your textbook describe layout managers? I notice that you haven't used any specific layout managers, so by default you're using (I think, but maybe I'm wrong) BorderLayouts for each of your panels. However it seems to me that choosing some other layout manager would make it much easier to control things in the way you're asked to.
Rusty Swain

Joined: May 09, 2014
Posts: 2
I have no idea what layout managers are let alone how to use them. I'm a bit of a noob to java.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2172
You can read up on layout managers from the Swing tutorial on Using Layout Managers.

I'm not really sure what the assignment is about because all your components are a fixed size so they will never grow. There will however change location within the frame as the frame is resized.

By default a JPanel uses a FlowLayout so you can read the tutorial to understand why the components changes location.

Regarding the other part of the question, I don't think you need the third panel. By default the content pane of a JFrame uses a BorderLayout. So try adding p1 to the NORTH and p2 to the CENTER to see if that makes a difference.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340

that should do it. the center will expand to take up any unused area.

Visit my download page
Don't get me started about those stupid light bulbs.
subject: Difficulty with panel sizing