Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Tooltip in Java

Posted on 1998-09-10
4
Medium Priority
?
498 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 200 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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

916 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