• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Buttons and Icons of different sizes cannot display centered.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a JTogglebutton and would like to add an ImageIcon to it.
Simple.
JToggleButton mybutton = new JToggleButton(new ImageIcon("bigger.jpg"));
now I want to add a SMALLER SIZED ImageIcon and set it as the selected Icon.
mybutton.setSelectedIcon(new ImageIcon("smaller.jpg"));
My problem is that since the bigger Icon is the default, when the smaller Icon gets displayed it gets drawn on the top left corner of the button instead of the middle, which is what I want.
SOmewhere the button keeps the starting coordinates of the default icon and uses the same starting coordinates to draw the smaller selectedIcon.
I guess I could exchange the icons myself by setting the selectedIcon as default, but I want to make use of the functionality that the button already has built in.
The answer should be something similar to the mybutton.setVerticalAlighment(SwingConstants.CENTER);
but this does not work.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check the Icon interface. this appears to let you set the cordinates for the icon.
http://java.sun.com/j2se/1.3/docs/api/javax/swing/Icon.html
good luck
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Utlg -
The name you've chosen to register does not conform to JavaRanch's naming policy. Please re-register using a proper name.
Thanks,
Michael
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A easier solution to this problem is to use gif files of same width and height and place the smaller icon on a transparent background.
Cheers,
Beno�t
 
reply
    Bookmark Topic Watch Topic
  • New Topic