如何隐藏在JScrollBar的箭头按钮 [英] How to hide the arrow buttons in a JScrollBar

查看:503
本文介绍了如何隐藏在JScrollBar的箭头按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要隐藏 <$的箭头按钮C $ C> java.awt.Scrollbar中(垂直)在AWT应用程序
有谁知道如何可以做到这一点?

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

我看到了一个例子<一个href=\"http://stackoverflow.com/questions/1786886/remove-arrows-from-swing-scrollbar-in-jscrollpane\">here,但code只是隐藏的按钮。为按钮保持静止的空置面积;它不是由滚动条所占据。

I saw an example here, but the code just hides the buttons. The vacant space for the buttons still remains; it is not occupied by the scroll bar.

要更确切地说,这里是我要达到什么样的屏幕截图。我不知道去了解它的方向。

To be more exact, here is the screenshot of what I should achieve. I am not sure which direction to go about it.

更新:我一直在寻找AWT的解决方案。但现在我愿意在Swing和建议。

Update : I was looking for a solution in AWT. But now I am open to suggestions in Swing as well.

推荐答案

试试这个..它取代了垂直滚动条的常规按钮与在尺寸为0x0的按钮。

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

这篇关于如何隐藏在JScrollBar的箭头按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆