• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jbutton background image

 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This code adds an image on top of jbutton:
Icon icon = new ImageIcon ("oval.png");
JButton back = new JButton(icon);

How can I change the size of the button so that it fits the image size.
Basically I am trying to create an oval button.

Thanks,
Cathy.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually a JButton should show up at the correct size to show all the image when you instantiate it with the ImageIcon. If you change the icon later you may have to call 'revalidate' on the button or its parent container. If the button is in a Container whose layout manager respects the preferred size of its components, eg, FlowLayout, GridBagLayout, this should work

You can use 'setBounds' if you need to get heavy-handed.
[ August 08, 2005: Message edited by: Craig Wood ]
 
Mahesh x Bogadi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use setPreferredSize(new Dimension(width, height))
 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Craig and Mahesh - that solution worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic