鼠标在带有图像显示的textarea上,鼠标光标释放后图像消失

时间:2013-07-19 19:39:25

标签: java image swing cursor mouse

如何在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);
    }
}

需要帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

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

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