jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes A JPanel doesn't extend fully in a BorderLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A JPanel doesn Watch "A JPanel doesn New topic
Author

A JPanel doesn't extend fully in a BorderLayout

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601

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

Joined: Jul 26, 2007
Posts: 10523
    
    9

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
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

Joined: Jul 26, 2007
Posts: 10523
    
    9

Your frame is set to 500,500
Your image rectangle is 800,100
See anything wrong here?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2216
    
    7
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

Joined: Jan 26, 2012
Posts: 149
    
    9
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

Joined: Aug 02, 2012
Posts: 601
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A JPanel doesn't extend fully in a BorderLayout