- 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
Advertisements