0

问候,

我想setDissmissDelay()多次设置方法。但我无法一次又一次地将其设置为特定值。我还尝试使用无限循环,尝试覆盖(ToolTipManager 构造函数在默认修饰符上)。我确定代码工作正常,因为我可以看到它e.getsource()在控制台中打印。我试图解决某人提出的这个问题(这个问题),在解决这个问题的同时,我在这一点上遇到了困难。这背后的原因是什么?如果我可以设置值怎么办?有没有其他方法可以实现这一目标?

这是我的代码片段:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.*;

public class Hello {
    static JButton button;

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        button = new JButton("Hello World");
        button.setToolTipText("Its a tool tip Experiment!");
        frame.getContentPane().add(button);
        button.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {

                if (e.getSource() == button) {
                    ActionListener tt = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            ToolTipManager.sharedInstance().setDismissDelay(
                                    1000);
                            System.out.println(e.getSource());
                        }
                    };
                    new Timer(100, tt).start();
                }
            }
        });
        frame.pack();
        frame.setVisible(true);

    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

请指导我完成这个。

4

1 回答 1

1

CallingsetDismissDelay()是一个全局设置,用于指示 Tooltip 在移除之前应在显示屏上保留多长时间。在删除当前工具提示之前,它不会重置时间。正如您在链接问题中所建议的那样,一劳永逸地设置解雇延迟Integer.MAX_VALUE应该可以解决问题。

于 2012-12-11T17:43:41.417 回答