jdk/test/javax/swing/JButton/6604281/bug6604281.java
author rupashka
Mon, 11 Aug 2008 16:39:17 +0400
changeset 1296 b42a874137fc
child 5506 202f599c92aa
permissions -rw-r--r--
6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build. Summary: Fixed calculation of preferred size in SynthButtonUI Reviewed-by: loneid, peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1296
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     1
/*
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     4
 *
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     8
 *
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    13
 * accompanied this code).
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    14
 *
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    18
 *
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    21
 * have any questions.
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    22
 */
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    23
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    24
/* @test
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    25
   @bug 6604281
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    26
   @summary NimbusL&F :Regression in Focus traversal in JFileChooser in pit build
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    27
   @author Pavel Porvatov
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    28
   @run main bug6604281
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    29
*/
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    30
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    31
import javax.swing.*;
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    32
import javax.swing.plaf.IconUIResource;
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    33
import javax.swing.plaf.synth.SynthLookAndFeel;
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    34
import java.awt.*;
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    35
import java.awt.image.BufferedImage;
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    36
import java.lang.reflect.InvocationTargetException;
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    37
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    38
public class bug6604281 {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    39
    public static void main(String[] args) throws InvocationTargetException, InterruptedException {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    40
        SwingUtilities.invokeAndWait(new Runnable() {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    41
            public void run() {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    42
                SynthLookAndFeel laf = new SynthLookAndFeel();
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    43
                try {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    44
                    UIManager.setLookAndFeel(laf);
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    45
                } catch (Exception e) {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    46
                    fail(e.getMessage());
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    47
                }
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    48
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    49
                // Prepare image
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    50
                BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    51
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    52
                Graphics2D graphics = (Graphics2D) image.getGraphics();
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    53
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    54
                graphics.setColor(Color.BLUE);
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    55
                graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    56
                graphics.setColor(Color.RED);
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    57
                graphics.drawLine(0, 0, image.getWidth(), image.getHeight());
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    58
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    59
                // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    60
                JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    61
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    62
                JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    63
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    64
                button2.setEnabled(false);
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    65
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    66
                if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    67
                    fail("Two similar buttons have different size");
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    68
                }
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    69
            }
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    70
        });
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    71
    }
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    72
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    73
    private static void fail(String s) {
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    74
        throw new RuntimeException("Test failed: " + s);
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    75
    }
b42a874137fc 6604281: NimbusL&F :Regression in Focus traversal in JFileChooser in pit build.
rupashka
parents:
diff changeset
    76
}