1
I found this code that works well for the button:
public class CustomJToolTipTest {
private JFrame frame;
public CustomJToolTipTest() {
initComponents();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CustomJToolTipTest();
}
});
}
private void initComponents() {
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
JButton button = new JButton("button") {
//override the JButtons createToolTip method
@Override
public JToolTip createToolTip() {
return (new CustomJToolTip(this));
}
};
button.setToolTipText("I am a button with custom tooltip");
frame.add(button);
frame.pack();
frame.setVisible(true);
}
}
class CustomJToolTip extends JToolTip {
public CustomJToolTip(JComponent component) {
super();
setComponent(component);
setBackground(Color.black);
setForeground(Color.red);
}
}
There is a frame with the fields to apply this ToolTip
.
How to adapt code to a field instead of a button?
This then arrow a custom tooltip with black color and red letters. You really need a custom tooltip (with different colors or sizes, degrade, images, animations, whatever) or just put a standard tooltip with a text to be defined by you is already great?
– Victor Stafusa
For me it’s enough to change the background and letters color but I’ve seen several examples out there that are even two or three lines of code but in mine it doesn’t work :S
– Hugo Machado
Yes, me too. I just wanted to know if you just need the text or need wrinkles too.
– Victor Stafusa
Just text. Can you change the color of the background and text only? If so, how? Thank you
– Hugo Machado