Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.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 为什么';我的滚动窗格没有滚动条吗?_Java_Swing_Applet_Jscrollpane - Fatal编程技术网

Java 为什么';我的滚动窗格没有滚动条吗?

Java 为什么';我的滚动窗格没有滚动条吗?,java,swing,applet,jscrollpane,Java,Swing,Applet,Jscrollpane,由于某些原因,我无法在小程序中显示滚动窗格 public void init() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JScrollPane scrPane = new JScrollPane(panel); scrPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); s

由于某些原因,我无法在小程序中显示滚动窗格

public void init() {
    JFrame frame = new JFrame(); 
    JPanel panel = new JPanel(); 
    JScrollPane scrPane = new JScrollPane(panel); 
    scrPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrPane.setLayout(new ScrollPaneLayout()); 
    frame.getContentPane().add(scrPane); 
    this.setVisible(true); 
}

您永远不会显示您创建的JFrame

这:

无法工作,因为您创建了JFrame,然后忽略了它

无论如何,您不应该让小程序显示JFrame。如果需要显示一个单独的窗口,请考虑显示一个对话框。更好的是,为什么不简单地将JScrollPane放在applet中呢

e、 g


scrPane.setLayout(新的ScrollPaneLayout())-不要玩布局。JScrollPane将自行设置布局。谢谢。就这样。我不知道这不是镜框。
frame.getContentPane().add(scrPane):
this.setVisible(true);   // this != frame
public void init() {
    //JFrame frame = new JFrame(); 

    JPanel panel = new JPanel(); 
    JScrollPane scrPane = new JScrollPane(panel); 
    scrPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    //  scrPane.setLayout(new ScrollPaneLayout()); 
    //  frame.getContentPane().add(scrPane); 

    getContentPane().add(scrPane);

    // this.setVisible(true); 
}