【问题标题】:Mouseover a textarea with an image display, after mouse cursor released image dissapear鼠标悬停在带有图像显示的文本区域上,鼠标光标释放后图像消失
【发布时间】:2013-07-19 19:39:25
【问题描述】:

如何在Java中鼠标光标指向文本区域后显示图像?

鼠标光标指向textarea MSR,MSSR...我需要显示一个图像,鼠标光标释放后图像消失

public class Report extends JFrame{
    JPanel table = new JPanel();
    JPanel process = new JPanel();
    JPanel all = new JPanel();
    JPanel north = new JPanel();
    JPanel south = new JPanel();
    JTextField MSR = new JTextField("AAA");
    JTextField MSSR = new JTextField("BBB");
    JTextField AAR = new JTextField("CCC");
    JTextField T10PAR = new JTextField("DDD");
    JLabel title = new JLabel("<HTML><u>Types Of Books</u></HTML>");

    Font myFont = new Font("Serif", Font.BOLD, 14);
    Font myFont1 = new Font("Times New Roman", Font.BOLD , 16);


    public Report(){
        north.setLayout(new FlowLayout(FlowLayout.LEFT));
        north.add(title);
        title.setFont(myFont1);
        add(north);
        table.setLayout( new GridLayout( 4, 1,1,7));

        table.add(MSR);
        MSR.setHorizontalAlignment(JTextField.CENTER);
        MSR.setBackground(Color.WHITE);    
        MSR.setPreferredSize(new Dimension(218,20));   
        MSR.setFont(myFont);    
        MSR.setForeground(Color.BLACK);
        MSR.setEditable(false);
        table.add(MSSR);
        MSSR.setHorizontalAlignment(JTextField.CENTER);
        MSSR.setBackground(Color.WHITE);    
        MSSR.setFont(myFont);    
        MSSR.setForeground(Color.BLACK);
        MSSR.setEditable(false);
        table.add(AAR);
        AAR.setHorizontalAlignment(JTextField.CENTER);
        AAR.setBackground(Color.WHITE);    
        AAR.setFont(myFont);    
        AAR.setForeground(Color.BLACK);
        AAR.setEditable(false);
        table.add(T10PAR);
        T10PAR.setHorizontalAlignment(JTextField.CENTER);
        T10PAR.setBackground(Color.WHITE);    
        T10PAR.setFont(myFont);    
        T10PAR.setForeground(Color.BLACK);
        T10PAR.setEditable(false);

        add(north,BorderLayout.NORTH);
        add(south,BorderLayout.SOUTH);    
        add(table,BorderLayout.WEST);
        add(process,BorderLayout.EAST);
    }
}

需要帮助。谢谢。

【问题讨论】:

  • 遵循 Java 命名约定。变量名称不应以大写字符开头。
  • 1) 为了尽快获得更好的帮助,请发帖 SSCCE。 2)请学习常用的Java naming conventions(特别是用于名称的大小写)类,方法和属性名称并一致地使用它们。

标签: java image swing cursor mouse


【解决方案1】:

您可以将 MouseAdapter 作为 MouseListener 添加到 JFrame,然后覆盖所需的方法。

http://docs.oracle.com/javase/6/docs/api/java/awt/event/MouseAdapter.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    相关资源
    最近更新 更多