changeset 10357:ba188ce09055 jdk-9+160

8089059: Left padding of CheckBox doesn't only add padding to the left, but also to top Reviewed-by: kcr
author aghaisas
date Thu, 02 Mar 2017 15:24:56 -0800
parents dad1d438d38a
children dd3f736d2b8e 77bfbbf9a00c 0a6cda7d625e
files modules/javafx.controls/src/main/java/javafx/scene/control/skin/CheckBoxSkin.java modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/CheckBoxSkinTest.java
diffstat 2 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/CheckBoxSkin.java	Thu Mar 02 17:02:48 2017 +0300
+++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/CheckBoxSkin.java	Thu Mar 02 15:24:56 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2017, 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
@@ -142,7 +142,7 @@
         final double labelHeight = Math.min(checkBox.prefHeight(labelWidth), h);
         final double maxHeight = Math.max(boxHeight, labelHeight);
         final double xOffset = Utils.computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
-        final double yOffset = Utils.computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + x;
+        final double yOffset = Utils.computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + y;
 
         layoutLabelInArea(xOffset + boxWidth, yOffset, labelWidth, maxHeight, checkBox.getAlignment());
         box.resize(boxWidth, boxHeight);
--- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/CheckBoxSkinTest.java	Thu Mar 02 17:02:48 2017 +0300
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/CheckBoxSkinTest.java	Thu Mar 02 15:24:56 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, 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
@@ -31,7 +31,12 @@
 import javafx.geometry.Insets;
 import javafx.scene.control.CheckBox;
 import javafx.scene.control.skin.CheckBoxSkin;
+import com.sun.javafx.tk.Toolkit;
+import javafx.scene.Group;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
 
+import org.junit.BeforeClass;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -40,6 +45,13 @@
 public class CheckBoxSkinTest {
     private CheckBox checkbox;
     private CheckBoxSkinMock skin;
+    private static Toolkit tk;
+    private Scene scene;
+    private Stage stage;
+
+    @BeforeClass public static void initToolKit() {
+        tk = Toolkit.getToolkit();
+    }
 
     @Before public void setup() {
         checkbox = new CheckBox("Test");
@@ -49,6 +61,11 @@
         checkbox.setPadding(new Insets(10, 10, 10, 10));
         checkbox.setSkin(skin);
 
+        scene = new Scene(new Group(checkbox));
+        stage = new Stage();
+        stage.setScene(scene);
+        stage.show();
+        tk.firePulse();
     }
 
     @Test public void maxWidthTracksPreferred() {
@@ -61,6 +78,17 @@
         assertEquals(500, checkbox.maxHeight(-1), 0);
     }
 
+    @Test public void testPadding() {
+        checkbox.setPadding(new Insets(10, 20, 30, 40));
+
+        tk.firePulse();
+
+        double expectedArea = checkbox.getHeight() * checkbox.getWidth();
+        double actualArea = checkbox.getSkin().getNode().computeAreaInScreen();
+
+        assertEquals(expectedArea, actualArea, 0.001);
+    }
+
     public static final class CheckBoxSkinMock extends CheckBoxSkin {
         boolean propertyChanged = false;
         int propertyChangeCount = 0;