JPanel: setToolTipText(String htmlString) : JPanel « javax.swing « Java by API






JPanel: setToolTipText(String htmlString)

  
import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolTip;

public class MainClass {

  public static void main(String args[]) {
    JFrame frame = new JFrame("Tooltip");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    panel.setToolTipText("<HtMl>Tooltip<br>Message");
    frame.add(panel, BorderLayout.CENTER);

    JButton button = new JButton("Hello, World") {
      public JToolTip createToolTip() {
        JToolTip tip = super.createToolTip();
        tip.setBackground(Color.YELLOW);
        tip.setForeground(Color.RED);
        return tip;
      }

      public boolean contains(int x, int y) {
        if (x < 100) {
          setToolTipText("x < 100");
        } else {
          setToolTipText("else");
        }
        return super.contains(x, y);
      }
    };
    
    button.setToolTipText("Hello, World");
    frame.add(button, BorderLayout.NORTH);

    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}


           
         
    
  








Related examples in the same category

1.JPanel: addAncestorListener(AncestorListener lis)
2.JPanel: addContainerListener(ContainerListener l)
3.JPanel: addMouseListener(MouseListener mous)
4.JPanel: addMouseMotionListener(MouseMotionListener lis)
5.JPanel: addKeyListener(KeyListener l)
6.JPanel: getFocusTraversalKeys(int id)
7.JPanel: isFocusCycleRoot()
8.JPanel: paintComponent(Graphics g)
9.JPanel: repaint()
10.JPanel: setBackground(Color c)
11.JPanel: setBorder(Border border)
12.JPanel: setComponentPopupMenu(JPopupMenu popup)
13.JPanel: setFocusCycleRoot(boolean value)
14.JPanel: setFocusTraversalPolicyProvider(boolean value)
15.JPanel: setLayout(null)
16.JPanel: setOpaque(boolean isOpaque)
17.JPanel: setPreferredSize(Dimension preferredSize)
18.extends JPanel