您所做的只是“隐藏”水平滚动条。这对管理组件的视口没有影响。
尝试将现有布局包装在Scrollable
界面中。如果您不想自己实现一个,则可以改用包装容器...
public class ScrollableWrapper extends JPanel implements Scrollable {
private Component wrapper;
public ScrollableWrapper(Component wrapper) {
setLayout(new BorderLayout());
add(wrapper);
this.wrapper = wrapper;
}
@Override
public Dimension getPreferredScrollableViewportSize() {
return wrapper.getPreferredSize();
}
@Override
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 64;
}
@Override
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 64;
}
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public boolean getScrollableTracksViewportHeight() {
return false;
}
}
然后,我们将其添加到滚动窗格中...
JSplitPane VPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,new class1(),new JScrollPane(new ScrollableWrapper(class2())));