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

ComponentOrientation.RIGHT_TO_LEFT and JScrollPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u24
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)



      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.32-29-generic #58-Ubuntu SMP Fri Feb 11 20:52:10 UTC 2011 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      When applying ComponentOrientation.RIGHT_TO_LEFT to a JScrollPane, one would expect the horizontal scrollbar to "lock" to the right side of the viewport when the enclosing window is resized. This is not the case. When resizing the window, the horizontal scrollbar position stays locked and the horizontal scrollbar extent decreases to the left, which causes the viewport to not move. With a RIGHT_TO_LEFT orientation, one would expect the horizontal scrollbar to reposition to compensate to keep the intended contents viewable in the viewport.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the attached source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With the button displaying "Right to Left", the expected outcome when resizing the window is to have the horizontal scrollbar's right side to stay "locked" and have the scrollbar's extent resize to the left, effectively scrolling the contents to the left.
      ACTUAL -
      The actual result is the horizontal scrollbar's left side is "locked" and the horizontal scrollbar's extent resizes to the right, effectively scrolling the contents to the right.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;

      import java.util.*;

      import javax.swing.*;

      public class ScrollBug
          extends JFrame {

          public ScrollBug() {
              super("Scroll Bug");

              Vector<String> data = new Vector<String>(50);

              for (int i = 0; i < 50; i++) {

                  data.add("item " + i);
              }

              final JList list = new JList(data) {

                  public Dimension getPreferredScrollableViewportSize() {

                      Dimension d = super.getPreferredScrollableViewportSize();

                      if (d.width > 500) {

                          d.width = 500;
                      }

                      return d;
                  }
              };

              final JButton change = new JButton("Right to Left");

              change.addActionListener(new ActionListener() {

                      public void actionPerformed(ActionEvent event) {

                          ComponentOrientation o = getComponentOrientation();
                          String t;

                          if (o == ComponentOrientation.RIGHT_TO_LEFT) {

                              o = ComponentOrientation.LEFT_TO_RIGHT;
                              t = "Left to Right";
                          } else {

                              o = ComponentOrientation.RIGHT_TO_LEFT;
                              t = "Right to Left";
                          }

                          applyComponentOrientation(o);
                          change.setText(t);
                      }
                  });

              list.setLayoutOrientation(JList.VERTICAL_WRAP);
              list.setVisibleRowCount(5);
              list.setFixedCellWidth(80);

              final JPanel buttons = new JPanel();

              buttons.add(change);

              final JScrollPane scroller = new JScrollPane(list);
              final JPanel contents = new JPanel(new BorderLayout());

              contents.add(scroller, BorderLayout.CENTER);
              contents.add(buttons, BorderLayout.SOUTH);

              setContentPane(contents);

              applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
          }

          public static void main(String[] args) {

              SwingUtilities.invokeLater(new Runnable() {

                      public void run() {

                          JFrame frame = new ScrollBug();
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          frame.pack();
                          frame.setVisible(true);
                      }
                  });
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: