Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Swing-带有自定义图形的滚动窗格_Java_Swing_Graphics_Awt - Fatal编程技术网

Java Swing-带有自定义图形的滚动窗格

Java Swing-带有自定义图形的滚动窗格,java,swing,graphics,awt,Java,Swing,Graphics,Awt,我现在有下面的代码 public class cRunningView extends JInternalFrame { static final int xOffset = 30, yOffset = 30; public cRunningView() { // Get name; super("RUNNING", true, // resizable false, // closable true, // maxi

我现在有下面的代码

public class cRunningView extends JInternalFrame {

    static final int xOffset = 30, yOffset = 30;
  public cRunningView() {
    // Get name;
    super("RUNNING", true, // resizable
            false, // closable
            true, // maximizable
            true);// iconifiable

    System.out.println("##" + "p.getName()");
    // ...Then set the window size or call pack...
    setSize(500, 200);

    // Set the window's location.
    setLocation(xOffset * 0, yOffset * 0);


    JScrollPane scrollPane = new JScrollPane();

}

}
我的目标是在屏幕的一半上有一个带有多个按钮和方框/矩形的JInternalFrame

在此框中,我希望能够绘制图形,例如从x,y到x,y绘制椭圆形

我试着看一些例子,但我发现自己比开始时更加困惑。我的所有代码都正常工作,例如显示主GUI窗口和打开内部框架,但我似乎找不到在JScrollPane中进行图形处理的好方法/起点

请注意,我不必使用JScrollPane,我只是觉得这是个好主意,因为它会给图形一个边框

在任何人抱怨这个问题之前,我认为它是有效的,我不想把代码放在盘子里给我,我宁愿知道和理解我在做什么,这样我才能提高我的知识水平,能够帮助别人

我必须再上一节课吗 JScrollPane myPane=JScrollPane(图形类)

然后使用paint()完成所有操作,或者是否有方法创建图形并在不使用其他类的情况下完成

如果我这样做:

JScrollPane scrollPane = new JScrollPane();
    Graphics temp = scrollPane.getGraphics();
    temp.setColor(new Color(1, 22, 33));
    temp.fillOval(60, 0, 120, 60);
    scrollPane.paint(temp);
它会抛出错误


谢谢

您不需要在滚动窗格中绘制图形。另外,不要使用getGraphics()方法进行自定义绘制

自定义绘制通过重写JPanel或JComponent的paintComponent()方法完成。然后,如果需要,您可以将面板添加到滚动窗格中,并将滚动窗格添加到框架中。不要忘记设置面板的首选大小,这样滚动就可以了


从阅读上的Swing教程开始。

如果绘制的图形大小超过JInternalFrame大小,是否还希望提供自动滚动选项?