Solved

Tooltip in Java

Posted on 1998-09-10
4
483 Views
Last Modified: 2013-12-14

 Hello friends ,

     JDK - 1.2 BETA 3

     I am a VC++ programmer. I am new to Java environment.
     I like to attach a tooltip message ( bubble window )
     in one of my java Control ( say Button ). How can
     i do that in Java. There should be a way to do that
     in Java. I know java is a powerful language. I can do
     anything in it. But i don't know how ? Please help
     me in this regards.

     Thanks in Advance.

     
0
Comment
Question by:sankars98
  • 2
4 Comments
 

Accepted Solution

by:
pureDan earned 100 total points
ID: 1224068
U've got to subclass Canvas (for instance) Why? U may simply want a subcomponent that U can use as a drawin' area ...(Canvas is a subclass of Component anyway)

Your custom component(button) class :

class MyButton extends Canvas
{
String str;
boolean button_up=true;
boolean mouse_down=false;

public MyButton(String str) {
     this.str=str;
}
public void paint (Graphics g)  {
if (button_up)  Draw_up(g);
else Draw_down(g);
}

public void Draw_up(Graphics g) {

  // draw what U want here

}

public void Draw_down(Graphics g) {

  // draw what U want here

}
 
public boolean mouseDown(Event e, int x, int y)  {
  Set_button_up(false);
  mouse_down=true;
  return true;                          }
}

public boolean mouseUp(Event e, int x, int y)  {
  Set_button_up(true);
  if (mouse_down)  b_clicked();
  mouse_down=false;
  return true;                          }
}

public boolean mouseEnter(Event e, int x, int y)  {
  if (mouse_down) Set_button_up(false);
  return true;                          }
}

public boolean mouseExit(Event e, int x, int y)  {
  if (mouse_down) Set_button_up(true);
  return true;                          }
}

public void Set_button_up(boolean b)  {
  if (  button_up != b)
       {
           button_up= b;
           repaint();
        }
}

public void b_clicked()  {
  Event ev= new Event(this,Event.ACTION_EVENT,str);
  postEvent(ev);
}

/******   the main class *********/

public class Butt_Modified extends Applet {
 public void init()  {

   /* put the layout here , so on */

    MyButton m_butt = new  MyButton("Blabla");
    add(m_butt);

   //  and so on ...
}
}

Maybe U can use this idea.

0
 

Expert Comment

by:pureDan
ID: 1224069
In the code above there's an idea how to use your own designed components. I suggest you to take a look on it...
and maybe U can solve your problem.

0
 
LVL 5

Expert Comment

by:fontaine
ID: 1224070
The Swing library that comes with JDK 1.2 (com.sun.java.swing... packages) contains all
you need to do very good GUI (as good as what MFCs allow, except that you have the
multiplatform capability of Java, pluggable look and feel, etc.) and is much more powerful
than AWT (much more components, amongst others). Any Swing component can
use the JComponent setToolTipText() method to specify the text for a standard tooltip.
A Swing button (JButton), for example, can have a tooltip, as it is a JComponent, as all
others Swing GUI components:

JButton button = new JButton("OK");
button.setTooltipText("Click me!");

Simple, isn't it? I recommend you the following link:

http://java.sun.com/docs/books/tutorial/ui/swing/tooltip.html

It could be worth posting here your impressions about the porting of your application (what
difficulties do you faced, etc.). Good luck.
0
 
LVL 4

Expert Comment

by:evijay
ID: 1224071
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 22
Weekend adv creator 3 39
how to add new optional parameter to JSP 1 43
eclipse buid path vs tomcat lib path 10 24
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question