• Post Reply Bookmark Topic Watch Topic
  • New Topic

Resizing the images in Jbuttons in Grid layout

 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Am trying to dynamically insert buttons (which will be presenting card in a frame) using grid layout.
As shown image is getting inserted but its not fit in button.


I tried Darryl's Stretch icon as well but of no help.



Any Suggestions ?

Any advice would be appreciated . Thanks.
 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PLease see the screen shot.I forgot to attach the image in previous post.
Image should be fit in buttons.Thanks
GridLayoutImage.png
[Thumbnail for GridLayoutImage.png]
Please see this.
 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions?
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue.
 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried <code>
BufferedImage bufImg = null;
try {
bufImg = ImageIO.read(this.getClass().getResource("/UnoColors/green/card10.png"));
} catch (IOException e) {
e.printStackTrace();
}
Image scaledImg = bufImg.getScaledInstance(btn.WIDTH, btn.HEIGHT, BufferedImage.SCALE_SMOOTH);



btn.setIcon(new ImageIcon(scaledImg));
panel_playerCards.add(btn);
panel_player1.revalidate();
panel_player1.repaint();
</code>


but of no use. Now it is not showing any image on button.
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grid layout gives you a grid of components, all the same size. You should not use grid layout if you want things to differ in size. What about grid bag?
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried Darryl's Stretch icon as well but of no help.


Did you look at the API? I believe the default behaviour is to maintain the aspect ration of the image. If you want the image to fill the entire space, which can cause distortion, then you need to use a different constructor.
 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your advice. BagGridlayout solved my purpose.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!