835N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
835N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
835N/A *
835N/A * This code is free software; you can redistribute it and/or modify it
835N/A * under the terms of the GNU General Public License version 2 only, as
835N/A * published by the Free Software Foundation.
835N/A *
835N/A * This code is distributed in the hope that it will be useful, but WITHOUT
835N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
835N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
835N/A * version 2 for more details (a copy is included in the LICENSE file that
835N/A * accompanied this code).
835N/A *
835N/A * You should have received a copy of the GNU General Public License version
835N/A * 2 along with this work; if not, write to the Free Software Foundation,
835N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
835N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
835N/A */
835N/A
835N/A/* @test
835N/A * @bug 6794836
835N/A * @summary BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
835N/A * @author Pavel Porvatov
835N/A * @run main bug6794836
835N/A */
835N/A
835N/Aimport javax.swing.*;
835N/Aimport javax.swing.plaf.basic.BasicSliderUI;
835N/Aimport java.lang.reflect.Method;
835N/Aimport java.util.Hashtable;
835N/A
835N/Apublic class bug6794836 {
835N/A public static void main(String[] args) throws Exception {
835N/A new bug6794836().run();
835N/A }
835N/A
835N/A public void run() throws Exception {
835N/A JSlider slider = new JSlider(0, Integer.MAX_VALUE);
835N/A
835N/A slider.setPaintLabels(true);
835N/A
835N/A JLabel minLabel = new JLabel("Min");
835N/A JLabel maxLabel = new JLabel("Max");
835N/A
835N/A Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
835N/A
835N/A labelTable.put(Integer.MIN_VALUE, minLabel);
835N/A labelTable.put(Integer.MAX_VALUE, maxLabel);
835N/A
835N/A slider.setLabelTable(labelTable);
835N/A
835N/A BasicSliderUI ui = (BasicSliderUI) slider.getUI();
835N/A
835N/A if (invokeMethod("getHighestValueLabel", ui) != maxLabel) {
835N/A fail("invalid getHighestValueLabel result");
835N/A }
835N/A
835N/A if (invokeMethod("getLowestValueLabel", ui) != minLabel) {
835N/A fail("invalid getLowestValueLabel result");
835N/A }
835N/A
835N/A System.out.println("The bug6794836 test passed");
835N/A }
835N/A
835N/A private static Object invokeMethod(String name, BasicSliderUI ui) throws Exception {
835N/A Method method = BasicSliderUI.class.getDeclaredMethod(name, null);
835N/A
835N/A method.setAccessible(true);
835N/A
835N/A return method.invoke(ui, null);
835N/A }
835N/A
835N/A private static void fail(String s) {
835N/A throw new RuntimeException("Test failed: " + s);
835N/A }
835N/A}