• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set the Tooltip text background & Foreground ?!!

 
Meghna ks
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
In swings, how do you set the Foreground and background colours for a swing component like a JButton, JLabel etc.
Thanks
Meghna
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meghana,
There is no default way to change foreground and background color of tooltips... however I did find a way to do it in a JFC book that I have... However, you have to make a new ToolTips class and new JComponents ( JButton, JLabel, etc. are all JComponents ) to use your new type of Tooltips. The new components have to override the createToolTip() method, like this :

and you would make your custom tool tips like this :

HTH,
-Nate
 
April.Johnson
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found a MUCH easier way to do this if you want all your tooltips to be the same color. Just put these lines in your code to change the tooltip background to black and the foreground to red.
UIManager.put("Tooltip.background", Color.black);
UIManager.put("Tooltip.foreground", Color.red);
Very handy. Easy to do. Thanks to Ana Mihailescu for pointing me in that direction when I asked about changing the selection color in a JComboBox.
April
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!