• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't display border (extends JPanel)

 
Greenhorn
Posts: 21
IntelliJ IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe i should ask again in the beginning java forum?
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thank you very much for your help, I'll have a look into all that ;D
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic