whats up?
Well, i'm trying to make my Pane a little bit better, visually, so, what i'm doing is: set my stage UNDECORATED (OK) and (TRYING) to add a dropshadow effect (NOT OK).
I Searched (A LOT) questions like this over the Internet, found some similar cases (creating undecorated stage in javafx 2.0 and How to add shadow to window in JavaFX?) but neither works for me.
It Seems like the drop shadow JUST don't is setted! Can't understand why.
See what i got:
public static int showConfirmDialog(Window father, String title, String body, String[] msgBtn)
{
System.out.println("La vai eu");
AnchorPane ap = createPaneWithButton(2, msgBtn,body);
ap.setEffect(initDropShadow());
Scene scene = new Scene(ap);
Stage stage = new Stage();
stage.setTitle(title);
scene.setFill(null);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
return 1;
}
private static AnchorPane createPaneWithButton(int qtBtn, String[] msgsBtn, String body) {
AnchorPane ap = createPane();
HBox laneBtn = new HBox(30);
VBox vbox = new VBox(20);
BorderPane layout = new BorderPane();
Button btn;
for(int i = 0; i < qtBtn; i++ ){
btn = new Button();
btn.setText(msgsBtn[i]);
laneBtn.getChildren().add(btn);
}
vbox.getChildren().add(new Text(body));
vbox.getChildren().add(laneBtn);
layout.setCenter(vbox);
ap.getChildren().add(layout);
return ap;
}
private static AnchorPane createPane() {
AnchorPane ap = new AnchorPane();
ap.setLayoutX(250);
ap.setLayoutY(50);
return ap;
}
Thank you guys! I'm looking forward for the response! (While i'll keep trying what i can).
PS:. Srry for the english, isn't my main language. Hope you can understand.
Well, I found a very simple solution. Maybe this was not supported in earlier versions? However.. The code:
The picture shows the result - my intention was to show a icon in the look of a FAB
Prior Example Works for Me
The example code supplied for the answer to How to add shadow to window in JavaFX? works fine for me (drop shadow on the dialog visible) on Java 8b96, Windows 7. When I wrote it for JavaFX 2, it also worked in that environment as well.
I couldn't say exactly what you are missing in your example as you did not provide full executable code.
Possible Issue with Your Code
My guess is that you are not insetting the background content so that there is space in the dialog for the shadow to be shown. That is, you are filling up the dialog with content and not leaving room in the dialog around the content for the effect to be displayed. The example below achieves the insetting with the css rule
-fx-background-insets: 12;
Updated Sample Code
I copied a modified version of the example code into this answer so that it isn't just contained in an obscure gist link off another answer. The modifications are to just use standard API calls as the builders used in the original answer have been deprecated since the original answer was created.
ModalConfirmExample.java
modal-dialog.css
Use a Library Instead
Also note that for creating dialogs I highly recommend using the ControlsFX project rather than creating your own dialog system. If ControlsFX lacks features which you require (such as drop shadow support), you can file a feature request for that against the ControlsFX project and link back to this answer if necessary.
Simple working example.
Here is
fxml
structure:Real
screen.fxml
:Main.java