• 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

JButton, icons and size.

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !
I have the follow problem.I have a button with a icon(gif) and no text, I set the icon with : button.setIcon(....).The icon size is 16,16 but my button is a little bit bigger that my icon.

What I need a "small" button - with the same size with its icon.

A solution is to use setPreferredSize method on my button(the pref. size is the icon size) but I not so "happy" with this.
The logic behind this is : if the button content(picure and/or text) size is smaller than the preffered size than the last one(pref. size) is used, the button takes its icon size only if the icon is bigger that its preffered size.

There are also other solutions/comments?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use setMargin(Insets). You will need to create an Insets object with values of like 1 or 0 for the amount of the inset so that your border is small or nill. I had to do this for JToolBar menus because, as you have found out, the margins are just too large.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ThanX a lot,it works and is also very logic.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic