我想将JScrollPane的一侧从右侧(默认)更改为左侧。我该怎么做呢?

AND:我想更改JScrollBar的大小,因为它是触摸屏(22“),以便可以轻松滚动。

非常感谢!

最佳答案

遵循@camickr建议的放置方式,这是一个完整的示例

import java.awt.*;
import javax.swing.*;
public class Test {
    public static void main(String[] args) {
        JFrame jf = new JFrame("Scorllbar test");
        JPanel jp = new JPanel() {{ add(new JComponent() {
                { setPreferredSize(new Dimension(450, 450)); }
                public void paintComponent(Graphics g) {
                    g.drawLine(0, 0, getWidth(), getHeight());
                    g.drawLine(getWidth(), 0, 0, getHeight());
                }});}};

        JScrollPane sp = new JScrollPane(jp,
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

        // Get the scroll-bar and make it a bit wider.
        JScrollBar sb = sp.getVerticalScrollBar();
        sb.setPreferredSize(new Dimension(50, 0));

        // Put it to the left.
        sp.remove(sb);
        JPanel tmp = new JPanel(new BorderLayout());
        tmp.add(sp, BorderLayout.CENTER);
        tmp.add(sb, BorderLayout.WEST);

        jf.add(tmp);
        jf.setSize(300, 300);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setVisible(true);
    }
}

10-08 02:24