How to hide the arrow buttons in a JScrollBar

前端 未结 2 1792
夕颜
夕颜 2021-01-02 15:56

I need to hide the arrow buttons of java.awt.Scrollbar(VERTICAL) in an AWT application. Does anyone know how this can be achieved?

I saw an example here, but the cod

2条回答
  •  青春惊慌失措
    2021-01-02 16:00

    Try this.. it replaces the regular buttons on the Vertical ScrollBar with buttons that are 0x0 in size.

    It does limit your look and feel though :(

    JScrollPane scroller = new JScrollPane(mainPane);
    scroller.setPreferredSize(new Dimension(200,200));
    // ... etc
    scroller.getVerticalScrollBar().setUI(new BasicScrollBarUI()
        {   
            @Override
            protected JButton createDecreaseButton(int orientation) {
                return createZeroButton();
            }
    
            @Override    
            protected JButton createIncreaseButton(int orientation) {
                return createZeroButton();
            }
    
            private JButton createZeroButton() {
                JButton jbutton = new JButton();
                jbutton.setPreferredSize(new Dimension(0, 0));
                jbutton.setMinimumSize(new Dimension(0, 0));
                jbutton.setMaximumSize(new Dimension(0, 0));
                return jbutton;
            }
        });
    

    Update: sorry, this is a swing solution

提交回复
热议问题