|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

06-11-2008, 10:10 AM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 83
|
|
|
Tooltip
I'm writing a program using swing applet.To the container i add the scrollPanle,to the i added panel above which i drawn my drawings...Now i want to add tooltip,when the mouse point goes over the drawing by showing its coordinates..Now i want to know how to add tooltip to the drawing?
Please help me....
|
|

06-11-2008, 10:22 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
You mean on the panel?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-11-2008, 11:51 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
If you JPanel is mainPanel try it as follows.
mainPanel.setToolTipText("Just for testings those text");
at the appropriate place of your code. Better to do it panel implementation.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-11-2008, 01:13 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 83
|
|
I tried in the way you said,but its not working out for me...Its not getting displayed....
public class NewClass
{
public void init()
{
Container cont = getContentPane();
cont.setLayout(new BorderLayout());
setPreferredSize(new Dimension(300, 300));
JScrollPane scroll = new JScrollPane();
getContentPane().add(scroll, BorderLayout.CENTER);
}
private class Imagepanel extends JPanel implements MouseListener,MouseMotionListener
{
panel();
addMouseMotionListener(this);
addMouseListener(this);
}
public void panel()
{
StartDate obj = new StartDate();
int w = obj.diff();
int dimension = 0;
int size = xmlreadingObj.getres_list().size();
int height = 100 + size * 28;
width = w;
System.out.println("width"+width);
setPreferredSize(new Dimension(width, height));
setBorder(BorderFactory.createLineBorder(Color.BLA CK, border));
l = new JLabel("HAI");
add(l,BorderLayout.EAST);
l.setVisible(true);
l.setLocation(100,50);
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASIN G,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawRect(100,200,15,20);
g2.drawRect(200,200,15,20);
}
public void mousePressed(MouseEvent e)
{
Point p = e.getPoint();
x_Pos = e.getX();
y_Pos = e.getY();
for(int j = 0; j < rects.length; j++)
{
if(rects[j].contains(p))
{
selectedindex = j;
selectedRect = rects[j];
dragging = true;
break;
}
}
}
public void mouseMoved(MouseEvent e)
{
Imagepanel image = new Imagepanel();
l = new JLabel();
Point p = e.getPoint();
if(rects[selectedindex].contains(p))
{
image.add(l);
image.setToolTipText("Just to test");
}
else
{
candisplay = false;
}
}
}
|
|

06-11-2008, 01:27 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
What is your Imagepanel do. Is it return a panel?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-11-2008, 01:37 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
See how this simple widow works.
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/**
*
* @author Eranga Tennakoon
*/
public class ToolTipDemo {
JPanel pan = new JPanel();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ToolTipDemo().createAndShowGUI();
}
});
}
private void createAndShowGUI() {
System.out.println("Created GUI on EDT? "+
SwingUtilities.isEventDispatchThread());
JFrame f = new JFrame("ToolTip Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pan.setToolTipText("This is a tool tip");
pan.setPreferredSize(new Dimension(250, 250));
f.add(pan);
f.pack();
f.setVisible(true);
}
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|