Sometimes one line of tool tip is not enough. You may want to try and play around with JToolTip, but if you in hurry this "little hack" can be handy.
With little of HTML plus CSS code you can work out various formats (font, colour, alignment, size etc.).
Multi-line ToolTipText
Kevingon commented: Excellent tip :D +1
import javax.swing.*;
import java.awt.*;
public class ModifyToolTip {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
JFrame frame = new JFrame("JToolTip Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JButton butt = new JButton("Hello, World");
butt.setPreferredSize(new Dimension(120,55));
butt.setToolTipText("<html><center><h1>Hello,</h1>"
+"<h2 style='color: red; font-style: italic;'>World</h2>"
+"<b>Modified<br/>ToolTipText</b></center>"
+"<br/>so simple.");
panel.add(butt);
frame.add(panel);
frame.setSize(300, 150);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Kevingon 0 Newbie Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.