Here's how you can do it:import javax.swing.*;
import java.awt.*;
public class MBTestApplication extends JFrame {
public MBTestApplication() {
JPanel customPanelForToolTip = new JPanel();
customPanelForToolTip.setBackground(Color.red); //just to prove it's there ;-)
//
eJButton b = new eJButton("Click Here", customPanelForToolTip);
b.setToolTipText(""); //just to get it to display tooltips
getContentPane().add(b);
}
//
public static void main(String[] args) {
JFrame f = new MBTestApplication();
f.setBounds(100,100,300,300);
f.show();
}
}
//
class eJButton extends JButton {
JPanel customToolTipPanel;
public eJButton(String s, JPanel toolTipPanel) {
super(s);
customToolTipPanel = toolTipPanel;
}
public JToolTip createToolTip() {
JToolTip tip = new eJToolTip(customToolTipPanel);
tip.setComponent(this);
tip.setPreferredSize(new Dimension(100,50));
return tip;
}
}
//
class eJToolTip extends JToolTip {
public eJToolTip(JPanel customToolTipPanel) {
super();
setLayout(new BorderLayout());
add(customToolTipPanel, BorderLayout.CENTER);
}
}