8078614: WindowsClassicLookAndFeel MetalComboBoxUI.getbaseLine fails with IllegalArgumentException
authoralexsch
Thu, 30 Apr 2015 14:04:39 +0400
changeset 30495 ab8287b4c789
parent 30494 a245f4430b4c
child 30496 aac453851104
8078614: WindowsClassicLookAndFeel MetalComboBoxUI.getbaseLine fails with IllegalArgumentException Reviewed-by: serb, azvegint, alexsch Contributed-by: Victor Dyakov <victor.dyakov@oracle.com>
jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
jdk/test/javax/swing/JComboBox/6632953/bug6632953.java
--- a/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java	Wed Apr 29 16:02:57 2015 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java	Thu Apr 30 14:04:39 2015 +0400
@@ -992,7 +992,7 @@
         getDisplaySize();
         if (sameBaseline) {
             Insets insets = c.getInsets();
-            height = height - insets.top - insets.bottom;
+            height = Math.max(height - insets.top - insets.bottom, 0);
             if (!comboBox.isEditable()) {
                 ListCellRenderer<Object> renderer = comboBox.getRenderer();
                 if (renderer == null)  {
--- a/jdk/test/javax/swing/JComboBox/6632953/bug6632953.java	Wed Apr 29 16:02:57 2015 -0700
+++ b/jdk/test/javax/swing/JComboBox/6632953/bug6632953.java	Thu Apr 30 14:04:39 2015 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,23 +22,39 @@
  */
 
 /* @test
- * @bug 6632953
+ * @bug 6632953 8078614
  * @summary MetalComboBoxUI.getBaseline(JComponent, int, int) throws IAE for valid width/height
  * @author Alexander Potochkin
  */
-
 import javax.swing.JComboBox;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
 import javax.swing.plaf.metal.MetalComboBoxUI;
 
 public class bug6632953 {
 
     public static void main(String... args) throws Exception {
-        MetalComboBoxUI ui = new MetalComboBoxUI();
-        ui.installUI(new JComboBox());
-        ui.getBaseline(new JComboBox(), 0, 0);
-        ui.getBaseline(new JComboBox(), 1, 1);
-        ui.getBaseline(new JComboBox(), 2, 2);
-        ui.getBaseline(new JComboBox(), 3, 3);
-        ui.getBaseline(new JComboBox(), 4, 4);
+        SwingUtilities.invokeAndWait(new Runnable() {
+
+            @Override
+            public void run() {
+
+                for (UIManager.LookAndFeelInfo lafInfo
+                        : UIManager.getInstalledLookAndFeels()) {
+                    try {
+                        UIManager.setLookAndFeel(lafInfo.getClassName());
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    MetalComboBoxUI ui = new MetalComboBoxUI();
+                    ui.installUI(new JComboBox());
+                    ui.getBaseline(new JComboBox(), 0, 0);
+                    ui.getBaseline(new JComboBox(), 1, 1);
+                    ui.getBaseline(new JComboBox(), 2, 2);
+                    ui.getBaseline(new JComboBox(), 3, 3);
+                    ui.getBaseline(new JComboBox(), 4, 4);
+                }
+            }
+        });
     }
 }