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

JList Scrollable block increment is incorrect for RTL

    XMLWordPrintable

    Details

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

      Description

      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() {
              super("ListIncrs");
              
              DefaultListModel model = new DefaultListModel();
              for (int i = 0; i < NUM_ITEMS; i++) {
                  model.addElement(new String("List Item " + i));
              }
              list = new JList(model);
              list.setVisibleRowCount(5);
              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);
              vertical.addActionListener(this);
              menu.add(vertical);

              verticalWrap = new JRadioButtonMenuItem("VERTICAL_WRAP", false);
              verticalWrap.addActionListener(this);
              menu.add(verticalWrap);

              horizWrap = new JRadioButtonMenuItem("HORIZONTAL_WRAP", false);
              horizWrap.addActionListener(this);
              menu.add(horizWrap);

              listLayout = new ButtonGroup();
              listLayout.add(vertical);
              listLayout.add(verticalWrap);
              listLayout.add(horizWrap);

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

              mb.add(menu);
              setJMenuBar(mb);

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

              setSize(400, 400);
          }

          public void actionPerformed(ActionEvent e) {
              Object source = e.getSource();
              if (source == vertical && vertical.isSelected()) {
                  list.setLayoutOrientation(JList.VERTICAL);
              }
              else if (source == verticalWrap && verticalWrap.isSelected()) {
                  list.setLayoutOrientation(JList.VERTICAL_WRAP);
              }
              else if (source == horizWrap && horizWrap.isSelected()) {
                  list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
              }
              else if (source == compOrient) {
                  if (compOrient.getState()) {
                      applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                  }
                  else {
                      applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
                  }
              }
              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();
              f.setVisible(true);
          }
      }
      ###@###.### 10/5/04 01:07 GMT

        Attachments

          Activity

            People

            Assignee:
            shickeysunw Shannon Hickey (Inactive)
            Reporter:
            bchristi Brent Christian
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: