JScrollPane:如何将滚动条向左移动并使视口在右侧对齐

JScrollPane: How to move the scroll bar to the left and have the viewport align on the right

如果我将 JScrollPane 滚动条放在左侧,则视口的左侧部分位于滚动条下方。

jScrollPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

如何将视口对齐到滚动条的右侧?

在这里找到答案:http://forums.codeguru.com/ 感谢拉夫克。 它工作正常。

jScrollPane.setLayout(new ScrollPaneLayout() {
    @Override
    public void layoutContainer(Container parent) {
        JScrollPane scrollPane = (JScrollPane) parent;
        scrollPane.setComponentOrientation(
            ComponentOrientation.RIGHT_TO_LEFT);
            super.layoutContainer(parent);
            scrollPane.setComponentOrientation(
                ComponentOrientation.LEFT_TO_RIGHT);
    }
});