• Post Reply Bookmark Topic Watch Topic
  • New Topic

Images as Components?

 
Nils Widmer
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a GridLayout, is it possible to add an Image to it so it would size it correctly when resize occurs etc?
------------------
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what you can do, is use the setConstraints, that way, when the window resizes and all the components resize, they keep the constraints that you set so it won't get all distorted. You still have to apply the image to a component though. Say for instanct a JLabel with an ImageIcon.
Hope that helps.
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to make it so that the image is resized to fit the new size of the component, you can do this easily. When drawing the image, use this method inside your JPanel:

The panel should automatically be repainted whenever the user resizes the containing window.
Hope that helps.
-Daniel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!