我有一个简单的程序,我将图像上传到java db数据库(只需将它们的位置及其类型添加到数据库中),然后我在滚动 Pane 中的程序中显示它们,问题是滚动 Pane 不是向下滚动,
这是我的代码
`
JPanel cont = new JPanel();
cont.setPreferredSize(new Dimension());
cont.setLayout(new FlowLayout(FlowLayout.LEFT));
while(sports_re.next()){
String location=sports_re.getString("LOCATIONN");
for(int i=0;i<100;i++){
JLabel picLabe = new JLabel();
picLabe.setIcon(new ImageIcon(new
ImageIcon(location).getImage().getScaledInstance(100, 100,
Image.SCALE_SMOOTH)));
cont.add(picLabe);
}
}
jScrollPane1.getViewport().setView(cont);
`
我尝试在尺寸中添加宽度和高度,它起作用了,但我必须输入一个巨大的数字才能使其起作用(如果我输入一个小数字,它将不允许我滚动)It's not right
this is what it looks like without the "cont.setPreferredSize(new Dimension());" 我想让它变得动态,请帮忙,谢谢
最佳答案
cont.setPreferredSize(new Dimension());
删除此项以便让 LayoutManager 计算大小。 TGhen 滚动 Pane 反射(reflect)计算的大小而不是您提供的固定大小。
关于java - 添加组件时滚动 Pane 不会下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43778990/