Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8364146

JList getScrollableUnitIncrement return 0

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The doc indicates return value is "always positive", but sometimes it return 0.


      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.awt.Rectangle;
      import javax.swing.JFrame;
      import javax.swing.JList;
      import javax.swing.JScrollPane;
      import javax.swing.SwingConstants;
      import javax.swing.SwingUtilities;

      public class JListTest {

          public static void main(String[] argv) throws Exception {
              SwingUtilities.invokeAndWait(() -> {
                  JFrame f = new JFrame();
                  String[] data = {"One", "Two", "Three", "Four", "Five", "Six ", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelv"};
                  JList<String> list = new JList<>(data);
                  list.setLayoutOrientation(JList.HORIZONTAL_WRAP);

                  JScrollPane sp = new JScrollPane(list);
                  sp.setPreferredSize(new Dimension(200, 200));
                  f.add(sp);
                  f.pack();
                  f.setVisible(true);

                  Rectangle cell = list.getCellBounds(0, 0);
                  int unit = list.getScrollableUnitIncrement(
                          cell,
                          SwingConstants.VERTICAL,
                          -1);
                  System.out.println("Scrollable unit increment: " + unit);

                  if (unit <= 0) {
                      throw new RuntimeException("JList scrollable unit increment should be greater than 0.");
                  }
                  f.dispose();
              });
          }
      }
      ---------- END SOURCE ----------

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: