Solved

Tooltip in Java

Posted on 1998-09-10
4
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

735 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