• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A JPanel doesn't extend fully in a BorderLayout

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This topBar seems to be a little bit shorter than the original image.
And the image isn't extend fully. Half of it is not shown in the JPanel
Thanks in advance
Jack
 
Maneesh Godbole
Saloon Keeper
Posts: 11066
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couple of things
1) Try the overriden paintComponent where you can specify the width and height of the rectangle on which the image is drawn
2) You are going to run into trouble with new File("images/topbar.png")); if you package your application in a jar. The correct way is to use getClass().getResource()
3) This is not a JavaFX question. Moving to the Swing forums
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Couple of things
1) Try the overriden paintComponent where you can specify the width and height of the rectangle on which the image is drawn
2) You are going to run into trouble with new File("images/topbar.png")); if you package your application in a jar. The correct way is to use getClass().getResource()
3) This is not a JavaFX question. Moving to the Swing forums


Thanks for your response,
I can't get it to work



Is the Border layout thing affecting the dimension of the JPanel?
 
Maneesh Godbole
Saloon Keeper
Posts: 11066
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your frame is set to 500,500
Your image rectangle is 800,100
See anything wrong here?
 
Rob Camick
Ranch Hand
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to display the image at its actual size then use a JLabel with an ImageIcon.

If you are trying to scale the image based on the size of the frame then use:


 
John Damien Smith
Ranch Hand
Posts: 287
13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a suggestion, don't mix JavaFX and Swing.

Just choose one GUI toolkit or the other and stick with it unless you absolutely have to mix them and you are completely sure of what you are doing.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Damien Smith wrote:As a suggestion, don't mix JavaFX and Swing.

Just choose one GUI toolkit or the other and stick with it unless you absolutely have to mix them and you are completely sure of what you are doing.


Thanks, I got it working now.
The image sizes don't match initially, now changed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic