Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li><p>AFAIK this could be done, possible by using <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html" rel="nofollow noreferrer">Swing Timer</a> and <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html" rel="nofollow noreferrer">PropertyChangeListener</a></p></li> <li><p>maybe there are another notifiers, code must be dealyed on some period, carefully with <code>E</code>(vent)<code>D</code>(ispath)<code>T</code>(hread) </p></li> <li><p>is required to use <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/SwingUtilities.html#convertMouseEvent%28java.awt.Component,%20java.awt.event.MouseEvent,%20java.awt.Component%29" rel="nofollow noreferrer">SwingUtilities.convertXxx</a> for <code>ToolTip</code> added to <code>JPanel</code>, <code>JPanel</code> which contains, there are added another <code>JComponents</code></p></li> <li><p>for example</p></li> </ul> <p><img src="https://i.stack.imgur.com/gg3vq.jpg" alt="."> <img src="https://i.stack.imgur.com/Fe61A.jpg" alt="enter image description here"></p> <pre><code>import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JToolTip; import javax.swing.Timer; import javax.swing.ToolTipManager; import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorListener; public class DynamicToolTipTest { private JPanel panel = new MyPanel(); private JFrame frame = new JFrame("DynamicToolTipTest"); public DynamicToolTipTest() { ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.setInitialDelay(200); ttm.setDismissDelay(10000); panel.setToolTipText("Text 1"); final Timer timer = new Timer(50, new ActionListener() { private int id = 1; @Override public void actionPerformed(ActionEvent e) { ++id; panel.setToolTipText("Text " + id); } }); timer.start(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.pack(); frame.setLocation(150, 100); frame.setVisible(true); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new DynamicToolTipTest(); } }); } private static final class MyPanel extends JPanel { private static final long serialVersionUID = 1L; @Override public Dimension getPreferredSize() { return new Dimension(300, 200); } @Override public JToolTip createToolTip() { final JToolTip tip = super.createToolTip(); final PropertyChangeListener updater = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent e) { if (e.getNewValue() != null) { tip.setTipText((String) e.getNewValue()); tip.repaint(); } } }; tip.addAncestorListener(new AncestorListener() { @Override public void ancestorAdded(AncestorEvent event) { //start listening for tip text changes only after the tip //is displayed, i.e. the tip is added to the component hierarchy MyPanel.this.addPropertyChangeListener(TOOL_TIP_TEXT_KEY, updater); } @Override public void ancestorRemoved(AncestorEvent event) { //stop listening for tip text changes once the tip is no longer //displayed, i.e. the tip is removed from the component hierarchy MyPanel.this.removePropertyChangeListener(TOOL_TIP_TEXT_KEY, updater); } @Override public void ancestorMoved(AncestorEvent event) { } }); return tip; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload