3

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

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

enter image description here

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

enter image description here

How can I set the thumb always visible?

enter image description here

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Alan
  • 33
  • 3
  • Seems okay to me. What version of Java are you using? Have you tried initialising the UI from within the context of the EDT ([Initial Threads](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html))? Do you have a screen shot of the two screens? – MadProgrammer Sep 30 '15 at 03:48
  • I'm using 1.8.0_60. Please see the following screenshot http://7xlpns.com1.z0.glb.clouddn.com/Nimbus%20300.png , http://7xlpns.com1.z0.glb.clouddn.com/Nimbus%20400.png , http://7xlpns.com1.z0.glb.clouddn.com/Metal%20300.png – Alan Sep 30 '15 at 05:14
  • I have tried running this demo in EDT thread, the problem exists. Thanks! – Alan Sep 30 '15 at 05:20
  • I'm running Windows 7/Java 8 and I don't have the problem, might be a Windows 8 related issue... – MadProgrammer Sep 30 '15 at 05:20
  • It's strange. I have tested on Win7/8 with JDK1.8.0_60. But they all have this problem. It only happened under Nimbus L&F, metal is OK. When you reduce the height of the frame, the thumb will disappear while there are enough space to display thumb. – Alan Sep 30 '15 at 05:58
  • This seems like the same issue here: [JDK-8134827 Scrollbar thumb disappears when display list is large - Java Bug System](https://bugs.openjdk.java.net/browse/JDK-8134827) – aterai Sep 30 '15 at 06:31
  • Does fixing [this](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html) help? – Catalina Island Sep 30 '15 at 10:20
  • Thanks you all. The following answer works. – Alan Oct 08 '15 at 02:37

2 Answers2

2

Try to set the minimum size of thumb to 1

getDefaults().put("ScrollBar.minimumThumbSize", new Dimension(29, 1));
San Droid
  • 332
  • 1
  • 7
  • Thanks, it works. I set `new Dimension(29, 29)` instead of `new Dimension(29, 1)` to make thumb bigger. – Alan Oct 08 '15 at 02:32
  • 1
    Ignore first comment, I was just to slow. `new Dimension(29,29)` is the default size of the thumb (look [here](https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html)). I tried it to set it to this size too but the thumb continue to disappeared after I add lot of new data to my test table. I guess because it can not be "shrink" by java I don't know. But it worked for me when I set the hight to 1. – San Droid Oct 08 '15 at 07:08
  • I still met some strange thing again. On my another PC, with a 1900*1000 screen, 1 and 29 are both not work. But when I set the height larger than 35, it works. Maybe this situation is relative with screen size, I'm not sure. Anyway, it works for me now. – Alan Oct 12 '15 at 09:42
  • 2
    It seems to be a [known](https://www.google.de/search?sclient=psy-ab&biw=983&bih=939&q=java+1.8.0_60+nimbus+thumb+issues&oq=java+1.8.0_60+nimbus+thumb+issues&gs_l=serp.3...145.11029.10.11237.26.24.1.1.1.0.112.1493.23j1.24.0....0...1c.1.64.serp..18.8.426.l_0DBmNr8Cc&pbx=1&cad=cbv&sei=h_xEVtDiDoX2Pt-qtNgJ) bug since 1.8.0_60 – San Droid Nov 12 '15 at 21:02
  • It is curious that Java has a problem with the default value of Dimension(29,29), but the answer by [Ariloum](http://stackoverflow.com/users/2542367/ariloum) did the trick for me (java 1.8_073-b02 win8.1). So his answer should be checked as right. – San Droid Feb 22 '16 at 15:32
2

You should try this:

UIManager.getLookAndFeelDefaults().put("ScrollBar.minimumThumbSize", new Dimension(30, 30));
Ariloum
  • 173
  • 1
  • 4