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

JList Scrollable block increment is incorrect for RTL



    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:


      The provided test case can be used to demonstrate a couple of problems with JList.getScrollableBlockIncrement() for JLists oriented right-to-left. Start by changing the settings so the list is layed out in VERTICAL_WRAP mode, and change the orientation to RIGHT_TO_LEFT.

      Problem #1: Drag the horizontal scroll bar all the way to the end (remember, that's the left side for RTL). Now click in the scroll track (to the right of the thumb) - the scrollbar should move by a page, and the list should scroll, but nothing happens. Do it as many times as you please - it won't move. You can press the Dump Scrollable Increments and see the problem - the Up block increment is 0. This problem was introduced sometime in 1.5.

      Problem #2: Drag the scroll bar back towards the top of the list (at the right). Arrange it so the right edge of the scrollpane is in the middle of a list item. Clicking in the scroll track is supposed to scroll by about a page, and realign the list so the edge of the scrollpane is in between list items, but the list remains unaligned. This problem has been present at least since 1.4. (This can also easily be seen in RTL JFileChoosers - I attached a separate test for that.).

      // A couple bugs in JList scrolling increments

      import javax.swing.*;
      import java.beans.*;
      import java.awt.*;
      import java.awt.event.*;

      public class ListIncrs extends JFrame implements ActionListener {
          private static final int NUM_ITEMS = 100;
          JList list;
          ButtonGroup listLayout;
          JRadioButtonMenuItem vertical;
          JRadioButtonMenuItem verticalWrap;
          JRadioButtonMenuItem horizWrap;
          JCheckBoxMenuItem compOrient;
          JButton dumpIncrs;
          public ListIncrs() {
              DefaultListModel model = new DefaultListModel();
              for (int i = 0; i < NUM_ITEMS; i++) {
                  model.addElement(new String("List Item " + i));
              list = new JList(model);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);

              JMenuBar mb = new JMenuBar();
              JMenu menu = new JMenu("Settings");
              menu.add(new JLabel("List Layout:"));

              vertical = new JRadioButtonMenuItem("VERTICAL", true);

              verticalWrap = new JRadioButtonMenuItem("VERTICAL_WRAP", false);

              horizWrap = new JRadioButtonMenuItem("HORIZONTAL_WRAP", false);

              listLayout = new ButtonGroup();

              menu.add(new JLabel("Component Orientation:"));
              compOrient = new JCheckBoxMenuItem("Right-To-Left");


              dumpIncrs = new JButton("Dump Scrollable Increments");
              getContentPane().add(dumpIncrs, BorderLayout.SOUTH);

              setSize(400, 400);

          public void actionPerformed(ActionEvent e) {
              Object source = e.getSource();
              if (source == vertical && vertical.isSelected()) {
              else if (source == verticalWrap && verticalWrap.isSelected()) {
              else if (source == horizWrap && horizWrap.isSelected()) {
              else if (source == compOrient) {
                  if (compOrient.getState()) {
                  else {
              else if (source == dumpIncrs) {
                  Rectangle visRect = list.getVisibleRect();
                  int orientation = list.getLayoutOrientation() == JList.VERTICAL ? SwingConstants.VERTICAL : SwingConstants.HORIZONTAL;
                  System.out.println("JList Scrollable Increments:");
                  System.out.println(" Unit Increment Up: " + list.getScrollableUnitIncrement(visRect, orientation, -1));
                  System.out.println(" Unit Increment Down: " + list.getScrollableUnitIncrement(visRect, orientation, 1));
                  System.out.println(" Block Increment Up: " + list.getScrollableBlockIncrement(visRect, orientation, -1));
                  System.out.println(" Block Increment Down: " + list.getScrollableBlockIncrement(visRect, orientation, 1));

          public static void main(String[] args) {
              ListIncrs f = new ListIncrs();
      ###@###.### 10/5/04 01:07 GMT




            shickeysunw Shannon Hickey (Inactive)
            bchristi Brent Christian
            0 Vote for this issue
            0 Start watching this issue