• Post Reply Bookmark Topic Watch Topic
  • New Topic

Minor alignment tweaking of icon on JLabel  RSS feed

 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My UI is set to Windows LAF, causing the folder icons in the nodes in a JTree to resemble the Windows folders. This works just great except for a slight difference in location of the Tree.closedIcon and Tree.openIcon: The latter is rendered about 2 pixels further up than the first, causing an annoying displacement of the icons when opening and closing the node. They're like bouncing up and down...

Actually it's not the rendering itself, it must be actual image file, as using


-doesn't cause the icons to bounce when opening and closing a node.

Well, I was wondering if there is an easy way to fix this, such as forcing the Tree.openIcon to be rendered 2 pixels further north than usual? I'm using a custom renderer for the nodes, so I have control at that point, but I cannot find anywhere to easily either set an Insets(2, 0, 0, 0) to the Tree.closedIcon or force a graphics2d.translate(-2, 0) for the Tree.openIcon.

One solution I'm thinking of is taking the


-and then create a new ImageIcon along with the graphics2d.translate(-2, 0) and use that icon for the Tree.openIcon, but wondering if there is an easier (and more ... correct?) way to fix the problem?


With kind regards,
Janus
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out JLabel#setIconTextGap(int gap). Default is 4 px.
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, this works splendidly:



 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Check out JLabel#setIconTextGap(int gap). Default is 4 px.


Hi Maneesh,

That would work for the gap between the icon and the text of the label. The problem is (or rather was, see above post) the vertical alignment of the icons.


Kind regards,
Janus
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!