如何用鼠标事件处理?当鼠标放在按钮上时,按钮显示提示信息?但鼠标离开按钮时提示信息也消失?

解决方案 »

  1.   


    <input type="button" value="open" title="this is a button" onMouseOut="" onMouseOver=""/>
    直接加上title,就能自动实现你的效果了,或者自己可以自定义弹出的样式,
    用onMouseOut和onMouseOver调用你想要表示和隐藏的div。
      

  2.   

    补充一下!我用的是swing,不过还得感谢flagiris(菖蒲芭芭)
      

  3.   

    lz说的不是Html种的“事件处理吧”。swing里面的?添加actionlistener就可以了。
      

  4.   

    http://blog.csdn.net/doymm2008/article/details/4820243
    这里讲的很清楚哈~
      

  5.   

    增加addMouseListener,里面有两个方法,mouseEntered(MouseEvent e) 鼠标进入组件时调用;
    mouseExited(MouseEvent e)鼠标离开组件时调用。
      

  6.   

    我知道用mouseEntered方法和mouseExited方法!但是我不知道在方法里写什么才会让它有提示信息!
      

  7.   

    你可以在上面加个label什么的,移上去让这个label显示,移走就隐藏呗。大概就这么做
      

  8.   

    button.setToolTipText(text);只要用这一个方法就行了!
      

  9.   

    用这个button.setToolTipText(text);方法,如何改变提示信息的背景颜色?
      

  10.   


    public class TestButton extends JFrame { private JButton jButton1; public TestButton() {
    initGUI();
    this.setLocationRelativeTo(null);
    } private void initGUI() {
    try {
    {
    getContentPane().setLayout(null);
    {
    jButton1 = new JButton();
    getContentPane().add(jButton1);
    jButton1.setText("test");
    jButton1.addMouseListener(new MouseAdapter() {
                                                     //鼠标进入事件
    public void mouseEntered(MouseEvent e) {
    jButton1.setText("move on");
    }
                                                    //鼠标移出事件
    public void mouseExited(MouseEvent e) {
    jButton1.setText("");
    }
    });
    jButton1.setBounds(109, 39, 161, 107);
    }
    }
    {
    this.setSize(426, 241);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    } public static void main(String args[]) {
    new TestButton().setVisible(true);
    }}
      

  11.   

    JieTouLangRen(哥只是个传说)很感谢你!不过我试了一下,不行!
      

  12.   

    这个可以啊,移上去有move on,移开就没了,楼主怎么不行了?
      

  13.   

    移上去是按钮上面有move on,
    我要的是当鼠标放到按钮上时!在按钮下面有个提示信息!当鼠标移开时提示信息也消失!
      

  14.   

    在eclipse里装windowbuilder 可以方便地可视化设计swing
    JButton btnNewButton = new JButton("New button");
    btnNewButton.setToolTipText("<html><body bgcolor='red'>move on</body></html>");http://topic.csdn.net/t/20061012/17/5078236.html