6128N/A/*
6128N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6128N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6128N/A *
6128N/A * This code is free software; you can redistribute it and/or modify it
6128N/A * under the terms of the GNU General Public License version 2 only, as
6128N/A * published by the Free Software Foundation.
6128N/A *
6128N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6128N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6128N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6128N/A * version 2 for more details (a copy is included in the LICENSE file that
6128N/A * accompanied this code).
6128N/A *
6128N/A * You should have received a copy of the GNU General Public License version
6128N/A * 2 along with this work; if not, write to the Free Software Foundation,
6128N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6128N/A *
6128N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6128N/A * or visit www.oracle.com if you need additional information or have any
6128N/A * questions.
6128N/A */
6128N/A
6128N/A/* @test
6128N/A @bug 7068740
6128N/A @summary JTable wrapped in JLayer can't use PGUP/PGDOWN keys
6128N/A @author Vladislav Karnaukhov
6128N/A @run main bug7068740
6128N/A*/
6128N/A
6128N/Aimport sun.awt.SunToolkit;
6128N/A
6128N/Aimport javax.swing.*;
6128N/Aimport javax.swing.plaf.LayerUI;
6128N/Aimport javax.swing.plaf.metal.MetalLookAndFeel;
6128N/Aimport javax.swing.table.DefaultTableModel;
6128N/Aimport java.awt.*;
6128N/Aimport java.awt.event.KeyEvent;
6128N/Aimport java.lang.reflect.InvocationTargetException;
6128N/A
6128N/Apublic class bug7068740 extends JFrame {
6128N/A
6128N/A private static Robot robot = null;
6128N/A private static JTable table = null;
6128N/A private static SunToolkit toolkit = null;
6128N/A
6128N/A bug7068740() {
6128N/A super();
6128N/A setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
6128N/A
6128N/A DefaultTableModel model = new DefaultTableModel() {
6128N/A @Override
6128N/A public int getRowCount() {
6128N/A return 20;
6128N/A }
6128N/A
6128N/A @Override
6128N/A public int getColumnCount() {
6128N/A return 2;
6128N/A }
6128N/A
6128N/A @Override
6128N/A public Object getValueAt(int row, int column) {
6128N/A return "(" + row + "," + column + ")";
6128N/A }
6128N/A };
6128N/A
6128N/A table = new JTable(model);
6128N/A LayerUI<JComponent> layerUI = new LayerUI<>();
6128N/A JLayer<JComponent> layer = new JLayer<>(table, layerUI);
6128N/A JScrollPane scrollPane = new JScrollPane(layer);
6128N/A add(scrollPane);
6128N/A pack();
6128N/A setLocationRelativeTo(null);
6128N/A }
6128N/A
6128N/A private static void setUp() {
6128N/A try {
6128N/A if (robot == null) {
6128N/A robot = new Robot();
6128N/A robot.setAutoDelay(20);
6128N/A }
6128N/A
6128N/A if (toolkit == null) {
6128N/A toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
6128N/A }
6128N/A
6128N/A SwingUtilities.invokeAndWait(new Runnable() {
6128N/A @Override
6128N/A public void run() {
6128N/A bug7068740 test = new bug7068740();
6128N/A test.setVisible(true);
6128N/A }
6128N/A });
6128N/A } catch (InterruptedException e) {
6128N/A e.printStackTrace();
6128N/A throw new RuntimeException("Test failed");
6128N/A } catch (InvocationTargetException e) {
6128N/A e.printStackTrace();
6128N/A throw new RuntimeException("Test failed");
6128N/A } catch (AWTException e) {
6128N/A e.printStackTrace();
6128N/A throw new RuntimeException("Test failed");
6128N/A }
6128N/A }
6128N/A
6128N/A private static void doTest() {
6128N/A toolkit.realSync();
6128N/A table.setRowSelectionInterval(0, 0);
6128N/A
6128N/A robot.keyPress(KeyEvent.VK_PAGE_DOWN);
6128N/A toolkit.realSync();
6128N/A if (table.getSelectedRow() != 19) {
6128N/A throw new RuntimeException("Test failed");
6128N/A }
6128N/A
6128N/A robot.keyPress(KeyEvent.VK_PAGE_UP);
6128N/A toolkit.realSync();
6128N/A if (table.getSelectedRow() != 0) {
6128N/A throw new RuntimeException("Test failed");
6128N/A }
6128N/A }
6128N/A
6128N/A public static void main(String[] args) {
6128N/A try {
6128N/A UIManager.setLookAndFeel(new MetalLookAndFeel());
6128N/A setUp();
6128N/A doTest();
6128N/A } catch (UnsupportedLookAndFeelException e) {
6128N/A e.printStackTrace();
6128N/A throw new RuntimeException("Test failed");
6128N/A }
6128N/A }
6128N/A}