Re: how to use ToolTip' functions on a Graphics area?
Vinicius Pereira wrote:
Hi Knute Johnson,
Yes, I already try this,
But how can I add a Graphics to the Panel?
This is my realy problem.
The example you posted to John shows a different tooltip based on the
location on the panel. That is very easily done by overriding the
JComponent.getToolTipText(MouseEvent) method. See the modified example
below.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JApplet {
public void init() {
JPanel p = new JPanel() {
public String getToolTipText(MouseEvent me) {
int x = me.getX();
int y = me.getY();
int halfH = getHeight() / 2;
int halfW = getWidth() / 2;
if (x < halfW && y < halfH)
return "Northwest";
else if (x > halfW && y < halfH)
return "Northeast";
else if (x < halfW && y > halfH)
return "Southwest";
else
return "Southeast";
}
};
p.setPreferredSize(new Dimension(100,75));
p.setBackground(Color.BLUE);
add(p);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test t = new test();
t.init();
f.add(t,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
});
}
}
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access