File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton, icons and size.

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ThanX a lot,it works and is also very logic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic