Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't display border (extends JPanel)  RSS feed

 
Uwe Pfeifer
Greenhorn
Posts: 21
Chrome IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm trying to make a border around a picture I display:



The border is not displayed my picture always uses the full width and height of the panel.
and



As you can see I use: picPanel.getWidth(), picPanel.getHeight(), java.awt.Image.SCALE_SMOOTH to get the height and width for my picture and it uses full size of the panel. But I want the panel to have a 10px border like the menu has.

Can anyone help me with this? Thank you!


 
Uwe Pfeifer
Greenhorn
Posts: 21
Chrome IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already tried:

newImage = image.getScaledInstance(picPanel.getWidth()-10, picPanel.getHeight(), java.awt.Image.SCALE_SMOOTH);

so -10 of the width but then it only shows a border in not the dark gray color of the panel on the rigth side of the panel, or an empty space or what it is.
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Query the panel's insets and use its left and top to start painting. You can also clip the graphics object:
Just remember that after clipping like this, you should use 0,0 to start painting. Apart from clipping, the create method also translates the graphics object.
 
Uwe Pfeifer
Greenhorn
Posts: 21
Chrome IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get insets? And what is to clip the graphics object? I don't really get this. And with draw on g2 do you mean i should do: g2.drawImage(image,0,0,this);?
Sorry, I'm totally new to this.
 
Uwe Pfeifer
Greenhorn
Posts: 21
Chrome IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe i should ask again in the beginning java forum?
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uwe Pfeifer wrote:How do I get insets?

Perhaps using the getInsets() method?

And what is to clip the graphics object? I don't really get this.

http://docs.oracle.com/javase/tutorial/2d/advanced/clipping.html
But you should probably read all of http://docs.oracle.com/javase/tutorial/2d/index.html.

And with draw on g2 do you mean i should do: g2.drawImage(image,0,0,this);?

Yes.
 
Uwe Pfeifer
Greenhorn
Posts: 21
Chrome IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thank you very much for your help, I'll have a look into all that ;D
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!