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

Resizing the images in Jbuttons in Grid layout  RSS feed

 
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: 21044
85
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
Sheriff
Posts: 55292
156
  • 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: 2787
12
  • 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!