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);
}