How to customize the tooltip in Java
To customize the tooltip in Java. We will use the UIManager to customize the ToolTip font, background, and foreground color in Java. UIManager manages the current look and feel.
The following code is a requirement for UIManager
import java.awt.Color; import java.awt.Font; import javax.swing.UIManager;
The following code shows how to customize the tooltip
private void jButton1MouseEntered(java.awt.event.MouseEvent evt) { jButton1.setToolTipText("This is ToolTipText"); //this is for customizing your tooltip UIManager.put("ToolTip.background", Color.white); UIManager.put("ToolTip.foreground", Color.black); UIManager.put("ToolTip.font", new Font("Century Gothic", Font.PLAIN, 14)); }
In my case, I used the UIManager inside MouseEvent. When the user enters/hovers the button, then the customized tooltip will fire.
We have set the background and foreground color with these lines of code
UIManager.put("ToolTip.background", Color.white); UIManager.put("ToolTip.foreground", Color.black); UIManager.put("ToolTip.font", new Font("Century Gothic", Font.PLAIN, 14));
As well as the font
UIManager.put("ToolTip.font", new Font("Century Gothic", Font.PLAIN, 14));
Thank you!