有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java无法在图像上绘制

实际上我需要做的是。。。 在图片上画(通常是大的)。我需要滚动图片在上面画画。 为此,我将图像(JLabel)添加到Jpanel中,并将Jpanel添加到JScrollPane中。 现在我可以滚动图像,但不能在上面画画。有人能帮我弄清楚吗!!这是我的密码`

    JFrame frame = new JFrame("Title");  
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(800, 800)); 

    JPanel panel = new JPanel(); 

    panel.add(new JLabel(new ImageIcon(image))); 

    JScrollPane jspane=new JScrollPane(panel);
    jspane.setViewportView(panel);
    jspane.add(this); //where i need to draw according to the mouse click
                      //when i tried frame.add(this); i was able to draw only on some  
                      //portion of the image but not able to scroll it.
    frame.add(jspane, BorderLayout.CENTER);

    frame.pack();  

    frame.setVisible(true);

共 (0) 个答案