Re: king of (re)setting the tooltipText as app runs
Larry Barowski wrote:
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);
}
}