How do I set a tool tip for swing component?

package org.kodejava.example.swing;

import javax.swing.*;
import java.awt.*;

public class ToolTipExample {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Tool Tip Demo");
        frame.setSize(200, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel label = new JLabel("Hover on me!");
        //
        // Setting tool tip for our Swing JLabel component
        //
        label.setToolTipText("My JLabel Tool Tip");

        frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
        frame.getContentPane().add(label);

        frame.setVisible(true);
    }
}

Wayan Saryada

Programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.

Leave a Reply