Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change side of a jScrollPane & change size

I want to change the side of my JScrollPane from the right (default) to the left side. How do I do this?

AND: I want to change the size of JScrollBar because it's a touch-display (22") so that it can be scrolled easily.

Thanks a lot!

like image 467
Christian 'fuzi' Orgler Avatar asked Dec 17 '10 20:12

Christian 'fuzi' Orgler


1 Answers

Following @camickr suggestion for the placement, here is a complete example

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);
    }
}

enter image description here

like image 73
aioobe Avatar answered Oct 23 '22 04:10

aioobe