• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

jbutton background image

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use setPreferredSize(new Dimension(width, height))
 
Cathy Song
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Craig and Mahesh - that solution worked
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic