public static void main(String[] args) throws InterruptedException { JFrame frame = new JFrame(); frame.setSize(400,300); frame.setLayout(new BorderLayout());
String rowdata[][] = new String[50][1]; for(int i=0;i<50;i++){ rowdata[i][0]=(i+1)+""; }
JTable table = new JTable(rowdata , new String[]{"col"}); final JScrollPane pane = new JScrollPane(table); frame.add(pane,BorderLayout.CENTER); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
JScrollBar bar = pane.getVerticalScrollBar(); int unit = bar.getMaximum() / table.getRowCount(); bar.setValue(unit * (25-1));
}
}
JScrollBar bar = pane.getVerticalScrollBar(); int unit = bar.getMaximum() / table.getRowCount(); bar.setValue(unit * (25-1)); 楼上说的没错,以前好象也是这么处理的,拉动滑块可以设置比例值
public class Test {
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame();
frame.setSize(400,300);
frame.setLayout(new BorderLayout());
String rowdata[][] = new String[50][1];
for(int i=0;i<50;i++){
rowdata[i][0]=(i+1)+"";
}
JTable table = new JTable(rowdata , new String[]{"col"});
final JScrollPane pane = new JScrollPane(table);
frame.add(pane,BorderLayout.CENTER);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JScrollBar bar = pane.getVerticalScrollBar();
int unit = bar.getMaximum() / table.getRowCount();
bar.setValue(unit * (25-1));
}
}
int unit = bar.getMaximum() / table.getRowCount();
bar.setValue(unit * (25-1));
楼上说的没错,以前好象也是这么处理的,拉动滑块可以设置比例值