This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 590

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: 10167
    
    8

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: 590
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: 10167
    
    8

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: 2152
    
    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: 130
    
    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: 590
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.
 
Consider Paul's rocket mass heater.
 
subject: A JPanel doesn't extend fully in a BorderLayout
 
Similar Threads
how to display text on image which keeps on getting changed ?
NetBeans IconImage
Getting Error
JDesktopPane creates inner frame menuItem actionPerformed does not.
How come JFXPanel doesn't show up?