Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BackgroundPanel.java cannot be placed in BorderLayout.NORTH

 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to put a picture on the top of my swing GUI that stretches horizontally to fit the width of the window as it resizes

http://www.camick.com/java/source/BackgroundPanel.java
this is the code for a commonly used function that scales images to their components size. it works by overloading the paintcontainer class, which is called every time the window resizes, which then calls the paint class. they simply grab the size of the container and draw the image to those dimensions

the image that needs to be resized must be placed in BorderLayout.NORTH, because the rest of my GUI is in BorderLayout.CENTER, but BackgroundPanel cant be placed in NORTH, the image disappears, even with a minimum size set. it cant be placed inside a panel inside a panel inside NORTH either. ive been reading over the code for BackgroundPanel and its driving me crazy i cant figure out why

here is some short example code, not my program but it simplifies the problem:
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chop ficaro wrote:

Puh-lease!
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chop ficaro wrote:

I really suggest you name your variables differently. Never use a class name as variable name. It makes your code confusing to read; when I first glanced over your code I thought I saw a few static calls:

Anyway, I see one problem with your BackgroundPanel. It has no children, so its size will be 0x0. Try giving it a preferred size.
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chop, you've been informed by both Darryl and me back in May that you should BeForthrightWhenCrossPostingToOtherSites.
 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
chop ficaro wrote:

I really suggest you name your variables differently. Never use a class name as variable name. It makes your code confusing to read; when I first glanced over your code I thought I saw a few static calls:

Anyway, I see one problem with your BackgroundPanel. It has no children, so its size will be 0x0. Try giving it a preferred size.



thats what this is
//panel.setMinimumSize( new Dimension( 224, 224 ) );
it doesnt work remove the comment mark and see
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you actually try doing what the suggestion was? We don't have time to keep repeating the same suggestion over and over (especially when you don't bother to reply to other postings when you get help).
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The minimum size is not the preferred size.
 
chop ficaro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tyvm! your suggestion fixed my problem!
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chop ficaro wrote:tyvm
Read this ( )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic