Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

king of (re)setting the tooltipText as app runs

Thread view: 
tek monk - 14 Sep 2006 01:14 GMT
I need to reset a JLabel's Text and TooTip as time passes in the simplest
and least taxing way.
.
I know for that you would use JLabel's setText(String ...) and
setToolTipText(String ...) methods, but the thing is that I do know, based
on the apps logic, when to call setText, but I don't know when a user is
going to place the mouse over the label
.
I have been thinking about some kind of time listener attached to the
JLabel, but I can't think of an elegant way of doing this.
.
How would you approach the solution to such a problem?
.
Thanks
Lee Weiner - 14 Sep 2006 04:27 GMT
> I need to reset a JLabel's Text and TooTip as time passes in the simplest
>and least taxing way.
[quoted text clipped - 6 lines]
> I have been thinking about some kind of time listener attached to the
>JLabel, but I can't think of an elegant way of doing this.

First you say that the ToolTip text changes as a function of time, then you
say you don't know when the user moves the mouse over the JLabel.?  Exactly
what is the trigger to change the text in the Tooltop?

Lee Weiner
lee AT leeweiner DOT org
onetitfemme - 14 Sep 2006 06:57 GMT
... "I do know, based on the apps logic, when to call setText" ...
.
that means, for example, if a user is supposed to read 50 invoices and
she clicks "Next" to go through them, the user is actually cliking on
the "Next" (or "Previous") button, so you know which invoice she is at
and change the label accordingly via setText, but say if you want to
know how much time she will need to finish reading all invoices (based
on reasonable heuristics, like the speed at which she has been reading
them + all of those that still need to be read ...)
.
I think you will have to capture/reimplement some kind of "mouse over"
action responsible for then setting the ToolTipText ...
.
onetitfemme
Larry Barowski - 14 Sep 2006 13:44 GMT
> I need to reset a JLabel's Text and TooTip as time passes in the simplest
> and least taxing way.
[quoted text clipped - 3 lines]
> on the apps logic, when to call setText, but I don't know when a user is
> going to place the mouse over the label ...

If you mean that you want to compute the text only when the tooltip
is about to be shown, then override  getToolTipText(MouseEvent) .
You will also need to do setToolTipText("dummy") to enable tooltips.
onetitfemme - 15 Sep 2006 02:23 GMT
> If you mean that you want to compute the text only when the tooltip
> is about to be shown, then override  getToolTipText(MouseEvent) .
> You will also need to do setToolTipText("dummy") to enable tooltips.
.
Exactly! and thank you for "understanding" me ;-)
.
For those of you trying the same thing here is some demo code that
updates the tooltip based on the current time:
.
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;

import java.awt.*;
import java.awt.event.*;

import java.util.*;
import java.text.*;

// __
public class ToolTipDemo00 extends JFrame{
JLabel JLbl;
SimpleDateFormat SDF;
// __
public ToolTipDemo00(){
 super();
 getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
 String aPttrn = "yyyyMMddHHmmss";
 SDF = new SimpleDateFormat(aPttrn);
 String aC = ":" + getFrmtdTm() + ":";
 JLbl = new JLabel(aC){
// __ Implement JLabel's tool tips.
  public String getToolTipText(MouseEvent MEvnt){
return(getFrmtdTm()); }
 };
 JLbl.setToolTipText(getFrmtdTm());

JLbl.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
 JLbl.setSize(100, 25);
 getContentPane().add(JLbl);
}
// __
public String getToolTipText() { return
ToolTipDemo00.this.getToolTipText(); }
// __
private String getFrmtdTm(){ return(SDF.format(new Date())); }
// __
public static void main(String[] args) {
 ToolTipDemo00 TTDm = new ToolTipDemo00();
 TTDm.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){ System.exit(0); }
 });
 TTDm.setSize(200, 150);
 TTDm.setVisible(true);
}
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.