Solved

Tooltip in Java

Posted on 1998-09-10
4
484 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
expectj telnet failing 5 45
add projects t working set in maven 2 16
Problem to Alipay 10 41
Where are the c++ header files to use in Eclipse? 4 23
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

791 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