本文介绍了JScrollBar在Nimbus L&F中不显示拇指的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个仅在Nimbus L&F上发生的问题.如果JList中的项目过多,则JScrollBar的拇指将消失.但是在金属L& F中,拇指始终是可见的,因为它的尺寸很小.我还检查了Nimbus L&F中的逻辑,确实有相同的最小大小.但这没有影响.

I got a problem which only happens on Nimbus L&F. If there are too many items in a JList, the thumb of JScrollBar will disappear. But in metal L&F, the thumb will be always visible, because it has a min size. I have also checked the logic in Nimbus L&F, there does have a same min size. But it not effected.

请在下面查看我的代码:

Please see my code below:

    public static void main(String[] args) {
    for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            try {
                UIManager.setLookAndFeel(info.getClassName());
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedLookAndFeelException ex) {
                Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
            }
            break;
        }
    }

    JFrame f = new JFrame("Metal (height 300)");

    String[] ss = new String[100];
    for (int i = 0; i < ss.length; i++) {
        ss[i] = "" + i;
    }

    JList<String> l = new JList<String>();
    l.setListData(ss);

    final JScrollPane jScrollPane = new JScrollPane(l);
    f.getContentPane().add(jScrollPane);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 300);
    f.setVisible(true);
}

当我设置"f.setSize(300,300);"时,拇指将消失.

When I set "f.setSize(300, 300);", the thumb will disappear.

但是,如果我设置"f.setSize(300,400);",则将显示拇指.

But if I set "f.setSize(300, 400);", the thumb will be visible.

如何设置拇指始终可见?

How can I set the thumb always visible?

推荐答案

尝试将拇指的最小尺寸设置为1

Try to set the minimum size of thumb to 1

getDefaults().put("ScrollBar.minimumThumbSize", new Dimension(29, 1));

这篇关于JScrollBar在Nimbus L&F中不显示拇指的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 20:43