- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we change the background and foreground color of a JTooltip in Java?
A JToolTip is a subclass of JComponent class and we can create a tooltip for any java component by using setToolTipText() method, it can be used to set up a tooltip for the component. The important methods of a JToolTip class are getAccessibleContext(), getComponent(), paramString() and updateUI(). We can change both the background and foreground color of a JToolTip class by using the put() method of UIManager class and pass the arguments ToolTip.background and ToolTip.foreground.
Example
import java.awt.*; import javax.swing.*; public class JTooltipColorTest extends JFrame { private JLabel label; public JTooltipColorTest() { setTitle("JTooltipColor Test"); setLayout(new FlowLayout()); label = new JLabel("Welcome to TutorialsPoint"); label.setToolTipText("Simply Easy Learning"); UIManager.put("ToolTip.background", Color.white); // to change background color of a JTtoolTip UIManager.put("ToolTip.foreground", Color.green); // to change foreground color of a JToolTip add(label); setSize(400, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public static void main(String[] args) { new JTooltipColorTest(); } }
Output
- Related Articles
- How to change JLabel background and foreground color in Java?
- How can we set the foreground and background color to JComboBox items in Java?
- How can we set the background/foreground color for individual column of a JTable in Java?
- Customize the tooltip font, color , background and foreground color in Java
- How to change the background and foreground colors of tab in Java?
- How can we set the background color to a JPanel in Java?
- How can we set a background color to JSplitPane in Java?
- How to change JFrame background color in Java
- How to change header background color of a table in Java
- How to change the Foreground Color of Text in C# Console?
- How to change the Foreground color or Font color of the console using PowerShell?
- Java Program to change the background color of rows in a JTable
- Java Program to customize MenuBar and change the background color
- How to change the background color of UIStackView?
- How to change the background color of a Treeview in Tkinter?

Advertisements