Results 1 to 5 of 5

Thread: Set ToolTip Text background color in java

  1. #1
    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.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    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));

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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();
      }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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();
    }
    }

Similar Threads

  1. Replies: 4
    Last Post: 20-12-2011, 06:16 PM
  2. Want to add text on a page having background color
    By Lakshmidhar in forum Software Development
    Replies: 4
    Last Post: 02-10-2010, 10:51 PM
  3. How to set the background color of JFrame?
    By kamina23 in forum Software Development
    Replies: 4
    Last Post: 13-02-2010, 06:42 PM
  4. JAVA Help - Background change by color matching
    By Daren in forum Software Development
    Replies: 4
    Last Post: 12-05-2009, 08:41 AM
  5. XP Color theme with dark window background color?
    By sayeed in forum Windows XP Support
    Replies: 4
    Last Post: 27-06-2008, 01:42 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,313,088.62309 seconds with 17 queries