Set the Tool Tip for a Tab in a JTabbedPane Container in Java

Description

The following code shows how to set the Tool Tip for a Tab in a JTabbedPane Container.

Example


import java.awt.BorderLayout;
//from   w  w w . ja  va  2  s .com
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;

public class Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    String label = "Tab Label";
    String tooltip = "Tool Tip Text";
    tabbedPane.addTab(label, null, new JButton("Button"), tooltip);
    int index = tabbedPane.getTabCount() - 1;
    tooltip = tabbedPane.getToolTipTextAt(index);
    tooltip = "New Tool Tip Text";
    tabbedPane.setToolTipTextAt(index, tooltip);
    
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
  }
}

The code above generates the following result.

Set the Tool Tip for a Tab in a JTabbedPane Container 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