-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
8, 9
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
Top padding is ignored, and left padding affects both top and left.
The bug appears to be in CheckBoxSkin on line 88:
87: final double xOffset = Utils.computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
88: final double yOffset = Utils.computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + x;
It should be + y instead of + x at the end of the line.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Set the top padding of the CheckBox to 10em and the rest to 0em.
2) Then try setting the left padding of the CheckBox to 10em and the rest to 0em.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1) The checkbox would move down.
2) There would be space on the left side of the checkbox only.
ACTUAL -
1) The CheckBox doesn't move.
2) The CheckBox moves 10em down and 10em right.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package checkboxpadding;
import com.sun.javafx.scene.control.skin.CheckBoxSkin;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author Dean
*/
public class CheckBoxPadding extends Application {
@Override
public void start(Stage primaryStage) {
HBox paddings = new HBox();
TextField top = new TextField("0");
TextField right = new TextField("0");
TextField bottom = new TextField("0");
TextField left = new TextField("0");
CheckBox check = new CheckBox("CheckBox for testing");
CheckBox check2 = new CheckBox("CheckBox with fixed skin.");
check.setStyle("-fx-background-color:red; -fx-padding: 0em 0em 0em 0em;");
check2.setStyle("-fx-background-color:blue; -fx-padding: 0em 0em 0em 0em;");
check2.setSkin(new FixedCheckBoxSkin(check2));
Button btn = new Button();
btn.setText("Set checkbox padding in em units.");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
check.setStyle(String.format("-fx-background-color:red; -fx-padding: %sem %sem %sem %sem;", top.getText(), right.getText(), bottom.getText(), left.getText()));
check2.setStyle(String.format("-fx-background-color:blue; -fx-padding: %sem %sem %sem %sem;", top.getText(), right.getText(), bottom.getText(), left.getText()));
}
});
VBox root = new VBox();
paddings.getChildren().addAll(top, right, bottom, left, btn);
root.getChildren().addAll(paddings, check, check2);
Scene scene = new Scene(root, 300, 500);
primaryStage.setTitle("CheckBox Padding Test");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
class FixedCheckBoxSkin extends CheckBoxSkin {
public FixedCheckBoxSkin(CheckBox checkbox) {
super(checkbox);
}
@Override
protected void layoutChildren(double x, double y, double w, double h) {
StackPane box = (StackPane) getChildren().get(1);
final CheckBox checkBox = getSkinnable();
final double boxWidth = snapSize(box.prefWidth(-1));
final double boxHeight = snapSize(box.prefHeight(-1));
final double computeWidth = Math.max(checkBox.prefWidth(-1), checkBox.minWidth(-1));
final double labelWidth = Math.min(computeWidth - boxWidth, w - snapSize(boxWidth));
final double labelHeight = Math.min(checkBox.prefHeight(labelWidth), h);
final double maxHeight = Math.max(boxHeight, labelHeight);
final double xOffset = computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
final double yOffset = computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + y;
layoutLabelInArea(xOffset + boxWidth, yOffset, labelWidth, maxHeight, checkBox.getAlignment());
box.resize(boxWidth, boxHeight);
positionInArea(box, xOffset, yOffset, boxWidth, maxHeight, 0, checkBox.getAlignment().getHpos(), checkBox.getAlignment().getVpos());
}
}
static double computeXOffset(double width, double contentWidth, HPos hpos) {
if (hpos == null) {
return 0;
}
switch (hpos) {
case LEFT:
return 0;
case CENTER:
return (width - contentWidth) / 2;
case RIGHT:
return width - contentWidth;
default:
return 0;
}
}
static double computeYOffset(double height, double contentHeight, VPos vpos) {
if (vpos == null) {
return 0;
}
switch (vpos) {
case TOP:
return 0;
case CENTER:
return (height - contentHeight) / 2;
case BOTTOM:
return height - contentHeight;
default:
return 0;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You can set the skin of the CheckBox to this skin:
class FixedCheckBoxSkin extends CheckBoxSkin {
public FixedCheckBoxSkin(CheckBox checkbox) {
super(checkbox);
}
@Override
protected void layoutChildren(double x, double y, double w, double h) {
StackPane box = (StackPane) getChildren().get(1);
final CheckBox checkBox = getSkinnable();
final double boxWidth = snapSize(box.prefWidth(-1));
final double boxHeight = snapSize(box.prefHeight(-1));
final double computeWidth = Math.max(checkBox.prefWidth(-1), checkBox.minWidth(-1));
final double labelWidth = Math.min(computeWidth - boxWidth, w - snapSize(boxWidth));
final double labelHeight = Math.min(checkBox.prefHeight(labelWidth), h);
final double maxHeight = Math.max(boxHeight, labelHeight);
final double xOffset = computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
final double yOffset = computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + y;
layoutLabelInArea(xOffset + boxWidth, yOffset, labelWidth, maxHeight, checkBox.getAlignment());
box.resize(boxWidth, boxHeight);
positionInArea(box, xOffset, yOffset, boxWidth, maxHeight, 0, checkBox.getAlignment().getHpos(), checkBox.getAlignment().getVpos());
}
}
static double computeXOffset(double width, double contentWidth, HPos hpos) {
if (hpos == null) {
return 0;
}
switch (hpos) {
case LEFT:
return 0;
case CENTER:
return (width - contentWidth) / 2;
case RIGHT:
return width - contentWidth;
default:
return 0;
}
}
static double computeYOffset(double height, double contentHeight, VPos vpos) {
if (vpos == null) {
return 0;
}
switch (vpos) {
case TOP:
return 0;
case CENTER:
return (height - contentHeight) / 2;
case BOTTOM:
return height - contentHeight;
default:
return 0;
}
}
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
Top padding is ignored, and left padding affects both top and left.
The bug appears to be in CheckBoxSkin on line 88:
87: final double xOffset = Utils.computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
88: final double yOffset = Utils.computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + x;
It should be + y instead of + x at the end of the line.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Set the top padding of the CheckBox to 10em and the rest to 0em.
2) Then try setting the left padding of the CheckBox to 10em and the rest to 0em.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1) The checkbox would move down.
2) There would be space on the left side of the checkbox only.
ACTUAL -
1) The CheckBox doesn't move.
2) The CheckBox moves 10em down and 10em right.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package checkboxpadding;
import com.sun.javafx.scene.control.skin.CheckBoxSkin;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author Dean
*/
public class CheckBoxPadding extends Application {
@Override
public void start(Stage primaryStage) {
HBox paddings = new HBox();
TextField top = new TextField("0");
TextField right = new TextField("0");
TextField bottom = new TextField("0");
TextField left = new TextField("0");
CheckBox check = new CheckBox("CheckBox for testing");
CheckBox check2 = new CheckBox("CheckBox with fixed skin.");
check.setStyle("-fx-background-color:red; -fx-padding: 0em 0em 0em 0em;");
check2.setStyle("-fx-background-color:blue; -fx-padding: 0em 0em 0em 0em;");
check2.setSkin(new FixedCheckBoxSkin(check2));
Button btn = new Button();
btn.setText("Set checkbox padding in em units.");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
check.setStyle(String.format("-fx-background-color:red; -fx-padding: %sem %sem %sem %sem;", top.getText(), right.getText(), bottom.getText(), left.getText()));
check2.setStyle(String.format("-fx-background-color:blue; -fx-padding: %sem %sem %sem %sem;", top.getText(), right.getText(), bottom.getText(), left.getText()));
}
});
VBox root = new VBox();
paddings.getChildren().addAll(top, right, bottom, left, btn);
root.getChildren().addAll(paddings, check, check2);
Scene scene = new Scene(root, 300, 500);
primaryStage.setTitle("CheckBox Padding Test");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
class FixedCheckBoxSkin extends CheckBoxSkin {
public FixedCheckBoxSkin(CheckBox checkbox) {
super(checkbox);
}
@Override
protected void layoutChildren(double x, double y, double w, double h) {
StackPane box = (StackPane) getChildren().get(1);
final CheckBox checkBox = getSkinnable();
final double boxWidth = snapSize(box.prefWidth(-1));
final double boxHeight = snapSize(box.prefHeight(-1));
final double computeWidth = Math.max(checkBox.prefWidth(-1), checkBox.minWidth(-1));
final double labelWidth = Math.min(computeWidth - boxWidth, w - snapSize(boxWidth));
final double labelHeight = Math.min(checkBox.prefHeight(labelWidth), h);
final double maxHeight = Math.max(boxHeight, labelHeight);
final double xOffset = computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
final double yOffset = computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + y;
layoutLabelInArea(xOffset + boxWidth, yOffset, labelWidth, maxHeight, checkBox.getAlignment());
box.resize(boxWidth, boxHeight);
positionInArea(box, xOffset, yOffset, boxWidth, maxHeight, 0, checkBox.getAlignment().getHpos(), checkBox.getAlignment().getVpos());
}
}
static double computeXOffset(double width, double contentWidth, HPos hpos) {
if (hpos == null) {
return 0;
}
switch (hpos) {
case LEFT:
return 0;
case CENTER:
return (width - contentWidth) / 2;
case RIGHT:
return width - contentWidth;
default:
return 0;
}
}
static double computeYOffset(double height, double contentHeight, VPos vpos) {
if (vpos == null) {
return 0;
}
switch (vpos) {
case TOP:
return 0;
case CENTER:
return (height - contentHeight) / 2;
case BOTTOM:
return height - contentHeight;
default:
return 0;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You can set the skin of the CheckBox to this skin:
class FixedCheckBoxSkin extends CheckBoxSkin {
public FixedCheckBoxSkin(CheckBox checkbox) {
super(checkbox);
}
@Override
protected void layoutChildren(double x, double y, double w, double h) {
StackPane box = (StackPane) getChildren().get(1);
final CheckBox checkBox = getSkinnable();
final double boxWidth = snapSize(box.prefWidth(-1));
final double boxHeight = snapSize(box.prefHeight(-1));
final double computeWidth = Math.max(checkBox.prefWidth(-1), checkBox.minWidth(-1));
final double labelWidth = Math.min(computeWidth - boxWidth, w - snapSize(boxWidth));
final double labelHeight = Math.min(checkBox.prefHeight(labelWidth), h);
final double maxHeight = Math.max(boxHeight, labelHeight);
final double xOffset = computeXOffset(w, labelWidth + boxWidth, checkBox.getAlignment().getHpos()) + x;
final double yOffset = computeYOffset(h, maxHeight, checkBox.getAlignment().getVpos()) + y;
layoutLabelInArea(xOffset + boxWidth, yOffset, labelWidth, maxHeight, checkBox.getAlignment());
box.resize(boxWidth, boxHeight);
positionInArea(box, xOffset, yOffset, boxWidth, maxHeight, 0, checkBox.getAlignment().getHpos(), checkBox.getAlignment().getVpos());
}
}
static double computeXOffset(double width, double contentWidth, HPos hpos) {
if (hpos == null) {
return 0;
}
switch (hpos) {
case LEFT:
return 0;
case CENTER:
return (width - contentWidth) / 2;
case RIGHT:
return width - contentWidth;
default:
return 0;
}
}
static double computeYOffset(double height, double contentHeight, VPos vpos) {
if (vpos == null) {
return 0;
}
switch (vpos) {
case TOP:
return 0;
case CENTER:
return (height - contentHeight) / 2;
case BOTTOM:
return height - contentHeight;
default:
return 0;
}
}
- duplicates
-
JDK-8089059 Left padding of CheckBox doesn't only add padding to the left, but also to top
-
- Resolved
-