Path: blob/master/test/jdk/javax/swing/JList/TestOpaqueListTable.java
41152 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.swing.JList;24import javax.swing.JTable;25import javax.swing.JToolTip;26import javax.swing.JTree;27import javax.swing.JViewport;28import javax.swing.LookAndFeel;29import javax.swing.SwingUtilities;30import javax.swing.UIManager;31import javax.swing.UnsupportedLookAndFeelException;3233/**34* @test35* @bug 8253266 826495036* @summary setUIProperty should work when opaque property is not set by37* client38* @key headful39* @run main TestOpaqueListTable40*/4142public class TestOpaqueListTable {4344public static void main(String[] args) throws Exception {45UIManager.LookAndFeelInfo[] installedLookAndFeels;46installedLookAndFeels = UIManager.getInstalledLookAndFeels();47for (UIManager.LookAndFeelInfo LF : installedLookAndFeels) {48try {49UIManager.setLookAndFeel(LF.getClassName());50SwingUtilities.invokeAndWait(() -> {51JList list = new JList();52JTable table = new JTable();53JTree tree = new JTree();54JToolTip toolTip = new JToolTip();55JViewport viewport = new JViewport();56String opaqueValue = new String(" ");5758if (!list.isOpaque()) {59opaqueValue += "JList, ";60}61if (!table.isOpaque()) {62opaqueValue += "JTable, ";63}64if (!tree.isOpaque()) {65opaqueValue += "JTree, ";66}67if (!toolTip.isOpaque()) {68opaqueValue += "JToolTip, ";6970}71if (!viewport.isOpaque()) {72opaqueValue += "JViewport, ";73}7475if(!opaqueValue.equals(" ")) {76throw new RuntimeException("Default value of " +77"\"opaque\" property for " + opaqueValue78+ " is changed ");79}8081LookAndFeel.installProperty(list, "opaque", false);82LookAndFeel.installProperty(table, "opaque", false);83LookAndFeel.installProperty(tree, "opaque", false);84LookAndFeel.installProperty(toolTip,"opaque",false);85LookAndFeel.installProperty(viewport,"opaque",false);8687opaqueValue = " ";88if (list.isOpaque()) {89opaqueValue += "JList, ";90}91if (table.isOpaque()) {92opaqueValue += "JTable, ";93}94if (tree.isOpaque()) {95opaqueValue += "JTree, ";96}97if (toolTip.isOpaque()) {98opaqueValue += "JToolTip, ";99}100if (viewport.isOpaque()) {101opaqueValue += "JViewport, ";102}103if (!opaqueValue.equals(" ")) {104throw new RuntimeException(105"setUIProperty failed to clear " +106opaqueValue +" opaque" +107" when opaque is not set by client");108}109110111list.setOpaque(true);112table.setOpaque(true);113tree.setOpaque(true);114toolTip.setOpaque(true);115viewport.setOpaque(true);116117LookAndFeel.installProperty(list,"opaque",false);118LookAndFeel.installProperty(table, "opaque", false);119LookAndFeel.installProperty(tree, "opaque", false);120LookAndFeel.installProperty(toolTip, "opaque", false);121LookAndFeel.installProperty(viewport, "opaque", false);122123opaqueValue = " ";124125if (!list.isOpaque()) {126opaqueValue += "JList";127}128if (!table.isOpaque()) {129opaqueValue += "JTable";130}131if (!tree.isOpaque()) {132opaqueValue += "JTree";133}134if (!toolTip.isOpaque()) {135opaqueValue += "JToolTip";136}137if (!viewport.isOpaque()) {138opaqueValue += "JViewport";139}140141if (!opaqueValue.equals(" ")) {142throw new RuntimeException("" +143"setUIProperty cleared the " +opaqueValue +144" Opaque when opaque is set by client");145}146147});148} catch (UnsupportedLookAndFeelException e) {149System.out.println("Note: LookAndFeel " + LF.getClassName()150+ " is not supported on this configuration");151}152}153}154}155156157