• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulty with panel sizing

 
Rusty Swain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21889
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4519
6
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that should do it. the center will expand to take up any unused area.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!