Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Displaying Positional Tooltip Text

import javax.swing.JButton; import javax.swing.JFrame; public class DisplayingPositionalTooltip {   public static void main(String args[]) {     JFrame frame = new JFrame();     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JButton button = new JButton("Hello, World") {       public boolean contains(int x, int y) {         if (x < 50) {           setToolTipText("AAAAAAAAA");         } else {           setToolTipText("BBBBBBBBBBBBBB");         }         return super.contains(x, y);       }     };     frame.add(button, "Center");     frame.setSize(300, 200);     frame.setVisible(true);   } }