Showing Multiple Lines in a Tool Tip in Java

Description

The following code shows how to showing Multiple Lines in a Tool Tip.

Example


  //from   w ww . ja  v  a  2  s . co  m
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {

  public static void main(String[] args) {

    JFrame frame = new JFrame();
    JLabel label = new JLabel("Label with image in Tooltip!");
    label.setToolTipText("<html>" + "This is a" + "<br>" + "tool tip" + "</html>");
    label.setHorizontalAlignment(JLabel.CENTER);
    frame.setContentPane(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(100, 100, 200, 100);
    frame.setVisible(true);

  }
}

The code above generates the following result.

Showing Multiple Lines in a Tool Tip in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer