Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

BackgroundPanel.java cannot be placed in BorderLayout.NORTH

 
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:
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

chop ficaro wrote:


Puh-lease!
 
Sheriff
Posts: 21866
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 21866
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
 
Rancher
Posts: 3140
27
  • 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
Posts: 21866
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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!
 
Marshal
Posts: 68145
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

chop ficaro wrote:tyvm

Read this ( )
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!