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

If you wrap a JTable in a JLayer you can't use the page up and page down cmds

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 7
    • 8
    • client-libs
    • b94
    • x86
    • windows_7

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.7.0"
        Java(TM) SE Runtime Environment (build 1.7.0-b147)
        Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        windows, linux

        A DESCRIPTION OF THE PROBLEM :
        Nothing happens when you page up and page down on a JTable wrapped in a JLayer in a JScrollPane. This is because of a problem in javax.swing.plaf.basic.BasicTableUI. If you look around line ~422 you will see this code:
        if (!(table.getParent().getParent() instanceof
                                    JScrollPane)) {
                                return;
                            }
        Because the table has been wrapped in a JLayer, the parents parent is not a JScrollPane. Maybe we should walk up the parents until we find a JScrollPane?

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the code below and try and use page up and page down buttons. They will not work.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Selected cell in table moves and scroll pane scrolls if required.
        ACTUAL -
        Table doesn't move and selected cell in table doesn't move.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package test;

        import javax.swing.*;
        import javax.swing.plaf.LayerUI;
        import javax.swing.table.DefaultTableModel;

        public class JLayerTableTest extends JFrame {
            public JLayerTableTest() {
                super("JLayer Table Test");
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                DefaultTableModel model = new DefaultTableModel() {
                    @Override public int getRowCount() {return 100;}
                    @Override public int getColumnCount() {return 3;}
                    @Override public Object getValueAt(int row, int column) {return "(" + row + "," + column + ")";}
                };
                JTable table = new JTable(model);
                LayerUI<JComponent> layerUI = new LayerUI<>();
                JLayer<JComponent> layer = new JLayer<>(table, layerUI);
                JScrollPane scrollPane = new JScrollPane(layer);
                add(scrollPane);
                pack();
                setLocationRelativeTo(null);
                setVisible(true);
            }

            public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override public void run() {new JLayerTableTest();}
                });
            }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        In my JTable I can override the getParent method and inspect the stack. If I am being called by the BasicTableUI in the appropriate method, I can return the parents parent. This works but getting the stack adversly affects the performance of the application.

        Attachments

          Issue Links

            Activity

              People

                vkarnauk Vladislav Karnaukhov
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: