Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-02-2010
Member
 
Join Date: Nov 2009
Posts: 712
Set ToolTip Text background color in java

Hello, I am learning java programming language and while working on it, I want to create a program which contains the tooltips. But, now I to provide color to that tooltip and I am not having any solution for that. So, if you are having any solution then please help me to get that. If you know any reference books from which I can able to know the basics of them then please help me to achive it.
Reply With Quote
  #2  
Old 24-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Set ToolTip Text background color in java

Hello, it is quiet simple thing to do. If you want to chage the tool tip colour then you just need to use the code for chaging the default value of the tooltip color. It is bydefault javax.swing.plaf.ColorUIResource[R=204,G=204,B=255]. For changing it to the one which you want you need to make use of the code below:
Code:
UIManager.put("Tooltip.background", new ColorUIResource(rvalue, gvalue, bvalue));
Reply With Quote
  #3  
Old 24-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Set ToolTip Text background color in java

Hello, I have read that you will able to get the solution for it, if you simply make use of the custom tools. So, just make use of it, and get your problem solved. If you use the custom tools then you can able to perform the setting the tooltip text background also. So, just perform it and get your problem solved. You need to just use the custom tools.
Reply With Quote
  #4  
Old 24-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Set ToolTip Text background color in java

Hello, I think it is necessary to simply make use of the code below and then you will able to get the solution for your problem:
Code:
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalLookAndFeel;

class checker extends MetalLookAndFeel 
{
  protected void initSystemColorDefaults(UIDefaults default) 
{
    super.initSystemColorDefaults(default);
    default.put("info", new ColorUIResource(255, 255, 225));
  }
}
class test extends JFrame
 {
  public test() throws Exception
{
    UIManager.setLookAndFeel("checker");
    setLayout(new FlowLayout());

    JButton b1 = new JButton();
    b1.setText("<html>A<br> B</html>");
    b1.setToolTipText("<html>C<br>D<br>E</html>");

    add(b1);

    JLabel l1 = new JLabel("Label");
    l1.setToolTipText("set");

    add(l1);
  }
  public static void main(String[] arg)throws Exception {
    test obj = new test();

    obj.setVisible(true);
    obj.setSize(new Dimension(300, 150));
    obj.validate();
  }
}
Reply With Quote
  #5  
Old 24-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: Set ToolTip Text background color in java

Hey, use the simple code below and you will able to get the solution for your problem. I have checked it, it is working as per your requirement:
Code:
import javax.swing.UIManager;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.Color;
public class backcolor
{
JButton b1=new JButton("Put your cursor on me");
JFrame f1=new JFrame("Set ToolTipText background color");
public backcolor()
{
 Color color=new Color(10,0,200);
 UIManager uim=new UIManager();
 uim.put("ToolTip.background",color);
 b1.setToolTipText("I am a button");
 f1.setLayout(new FlowLayout());
 f1.add(b1);
 f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 f1.setSize(400,400);
 f1.setLocationRelativeTo(null);
 f1.setVisible(true);
}
public static void main(String[]args)
{
 backcolor bc=new backcolor();
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Set ToolTip Text background color in java"
Thread Thread Starter Forum Replies Last Post
Text on desktop icons has background color - not transparent Syker Windows XP Support 4 20-12-2011 06:16 PM
Want to add text on a page having background color Lakshmidhar Software Development 4 02-10-2010 10:51 PM
How to set the background color of JFrame? kamina23 Software Development 4 13-02-2010 06:42 PM
JAVA Help - Background change by color matching Daren Software Development 4 12-05-2009 08:41 AM
XP Color theme with dark window background color? sayeed Windows XP Support 4 27-06-2008 01:42 AM


All times are GMT +5.5. The time now is 06:21 AM.