Reputation: 31
I'd like to slightly round the corners of a JavaFX PopupControl.
Below is a simple recreation of what I've tried:
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
PopupControl pu = new PopupControl();
pu.setStyle("-fx-background-radius: 10 10 10 10");
pu.setStyle("-fx-border-radius: 10 10 10 10");
VBox vb = new VBox();
vb.setPrefWidth(300);
vb.setPrefHeight(200);
vb.setStyle("-fx-background-color: rgba(17, 230, 120, 1.0)");
pu.getScene().setRoot(vb);
stage.setWidth(600);
stage.setHeight(500);
stage.show();
pu.show(stage);
Here is what's being shown:
For clarification, the corners of the green PopupControl are what I'm trying to round off.
Any help is appreciated.
Upvotes: 1
Views: 256
Reputation: 209684
Note that the style is a single property, so when you call pu.setStyle(...)
twice, the second style replaces the previous style; it doesn't add to it.
You need to set the background radius on the same container as you set the background color. The following works:
public void start(Stage stage) {
PopupControl pu = new PopupControl();
VBox vb = new VBox();
vb.setPrefWidth(300);
vb.setPrefHeight(200);
vb.setStyle("-fx-background-color: rgba(17, 230, 120, 1.0); " +
"-fx-background-radius: 10 10 10 10 ;");
pu.getScene().setRoot(vb);
stage.setWidth(600);
stage.setHeight(500);
stage.show();
pu.show(stage);
}
Setting the styles in an external style sheet is preferred, and probably easier.
Upvotes: 5