在頁面設計中,滾動面板用到的次數非常的頻繁,比如表格中字段過多的時候就需要用到滾動面板
使用代碼如下:
JScrollPane jspanel = new JScrollPane(
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JViewport view = new JViewport() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
setBackground(Color.WHITE);
}
};
jspanel.setViewport(view);
Component.setAutoResizeMode(Component.AUTO_RESIZE_OFF);//必須設置,否則不出現滾動條
jspanel.setViewportView(Component);//將控件加入到滾動面板
Component是你需要放入到滾動面板的控件,一般都是表格比較多,或者樹表比較多