我正在尝试让JScroll从顶部开始,但是它总是从结尾开始。我在互联网上发现了这么多解决方案,但对我不起作用。谁能在这段代码中告诉我问题?
这是课程:
public class BuildPanel extends JPanel{
GameSideCore gsc;
JPanel panel;
JScrollPane spane;
ArrayList<BuildPanelL> newPanels = new ArrayList<>();
public BuildPanel(GameSideCore gsc){
this.gsc = gsc;
setSize(640,240);
setBackground(Color.blue);
setLayout(null);
panel = new JPanel();
panel.setPreferredSize(new Dimension(600, 0));
panel.setLayout(null);
spane = new JScrollPane(panel);
spane.setPreferredSize(new Dimension(getWidth(),getHeight()));
spane.setBounds(0, 0, 640, 240);
spane.getVerticalScrollBar().setUnitIncrement(12);
JScrollBar jsBar = spane.getVerticalScrollBar();
jsBar.setValue(spane.getVerticalScrollBar().getMinimum());
spane.setVerticalScrollBar(jsBar);
add(spane);
}
public void BPanel(){
panel.removeAll();
System.out.println("BPanel");
for(int i = 1; i < 30; i++){
for(int m = 0; m < 30; m++){
if( gsc.location[m] == i){
newPanels.add(new BuildPanelL(i));
break;
}
}
}
panel.setPreferredSize(new Dimension(600, newPanels.size()*121));
for(int i = 0; i < newPanels.size(); i++){
panel.add(newPanels.get(i));
newPanels.get(i).setBounds(0, 0+i*121, 600, 120);
System.out.println("This is ."+i);
}
repaint();
}
}