Solved

Tooltip in Java

Posted on 1998-09-10
4
477 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 59
return in catch statement 1 39
java set up 1 44
How search webpage "viewable text" only 1 24
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now