Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javafx 2 在未装饰的窗格中放置阴影_Javafx 2_Dropshadow - Fatal编程技术网

Javafx 2 在未装饰的窗格中放置阴影

Javafx 2 在未装饰的窗格中放置阴影,javafx-2,dropshadow,Javafx 2,Dropshadow,我试图使我的窗格在视觉上更好一点,所以,我正在做的是:将我的舞台设置为未装饰(OK)和(尝试)添加阴影效果(不OK) 我发现了一些类似的案例,但都不起作用 看起来阴影还没有设定好。我不明白为什么 这就是我所拥有的: public static int showConfirmDialog(Window father, String title, String body, String[] msgBtn) { System.out.println("La vai eu&

我试图使我的窗格在视觉上更好一点,所以,我正在做的是:将我的舞台设置为未装饰(OK)和(尝试)添加阴影效果(不OK)

我发现了一些类似的案例,但都不起作用

看起来阴影还没有设定好。我不明白为什么

这就是我所拥有的:

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;
}


前面的示例适用于我

在Java 8b96和Windows 7上,为回答提供的选项对我来说很好(在对话框上显示阴影)。当我为JavaFX2编写它时,它也在那个环境中工作

我不能确切地说您在示例中缺少了什么,因为您没有提供完整的可执行代码

您的代码可能存在问题

我的猜测是,您没有插入背景内容,以便在对话框中有空间显示阴影。也就是说,您正在用内容填充对话框,而不是在对话框中围绕内容留出空间以显示效果。下面的示例使用css规则
-fx background insets:12实现插入

更新的样本代码

我将示例代码的一个修改版本复制到这个答案中,这样它就不会仅仅包含在另一个答案的一个模糊的要点链接中。这些修改只是使用标准API调用,因为自原始答案创建以来,原始答案中使用的构建器已被弃用

ModalConfirmExample.java

改用库


还要注意,对于创建对话框,我强烈建议使用项目,而不是创建自己的对话框系统。如果ControlsFX缺少您所需的功能(如投影支持),您可以针对ControlsFX项目对此进行验证,并在必要时链接回此答案。

嗯,我发现了一个非常简单的解决方案。可能这在早期版本中不受支持? 然而。。守则:

iconPane.setEffect(new DropShadow(2d, 0d, +2d, Color.BLACK));
这张图片显示了结果——我的意图是在一个图标的外观中显示一个图标

简单的工作示例

以下是
fxml
结构:

AnchorPane(200,200) // pane for space for shadow
    \- AnchorPane(center) // appliction pane
         \- Label // application content
Real
screen.fxml

<AnchorPane fx:id="shadowPane" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane fx:id="rootPane" layoutX="56.0" layoutY="62.0">
         <children>
            <Label fx:id="someLabel" layoutX="30.0" layoutY="30.0" text="Label" textFill="#f20000" />
         </children>
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
      </AnchorPane>
   </children>
</AnchorPane>

无FXML的后台dropshadow:

public void start(Stage stage){
    final double RADIUS = 5;
    VBox rootNode = new VBox();
    Insets bgInsets = new Insets(RADIUS);
    BackgroundFill bgFill = new BackgroundFill(Color.PINK, null, bgInsets);
    rootNode.setBackground(new Background(bgFill));
    DropShadow dropShadow = new DropShadow(RADIUS, Color.GRAY);
    rootNode.setEffect(dropShadow);

    Scene scene = new Scene(rootNode);
    scene.setFill(Color.TRANSPARENT);
    stage.setScene(scene);
    stage.initStyle(StageStyle.TRANSPARENT);
    stage.show();
}

让我们看看initDropShadow()。伙计,我知道*@&#我爱你!哈哈!!我刚刚添加了-fx背景插图!它解决了问题!哦,天哪。。只是觉得花了我几个小时。。。谢谢你!!愿奥丁保佑你@加布里埃尔·洛佩斯:是的,当我阅读他的答案时,我也会有同样的反应。我想说的是,应该在根窗格中添加-fx填充
iconPane.setEffect(new DropShadow(2d, 0d, +2d, Color.BLACK));
AnchorPane(200,200) // pane for space for shadow
    \- AnchorPane(center) // appliction pane
         \- Label // application content
<AnchorPane fx:id="shadowPane" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane fx:id="rootPane" layoutX="56.0" layoutY="62.0">
         <children>
            <Label fx:id="someLabel" layoutX="30.0" layoutY="30.0" text="Label" textFill="#f20000" />
         </children>
         <padding>
            <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
         </padding>
      </AnchorPane>
   </children>
</AnchorPane>
@Override
public void start(Stage stage) throws Exception {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/sample/screen.fxml"));
    AnchorPane shadowPane = loader.load();
    AnchorPane rootPane = (AnchorPane) shadowPane.lookup("#rootPane");
    rootPane.setStyle("-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.4), 10, 0.5, 0.0, 0.0);" +
                      "-fx-background-color: white;"); // Shadow effect

    Scene scene = new Scene(shadowPane);
    stage.setScene(scene);

    shadowPane.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.SOLID, null, null))); // Some borders for for clarity

    shadowPane.setStyle("-fx-background-color: transparent;"); // Makes shadowPane transparent
    scene.setFill(Color.TRANSPARENT); // Fill our scene with nothing
    stage.initStyle(StageStyle.TRANSPARENT); // Important one!
    stage.show();
}
public void start(Stage stage){
    final double RADIUS = 5;
    VBox rootNode = new VBox();
    Insets bgInsets = new Insets(RADIUS);
    BackgroundFill bgFill = new BackgroundFill(Color.PINK, null, bgInsets);
    rootNode.setBackground(new Background(bgFill));
    DropShadow dropShadow = new DropShadow(RADIUS, Color.GRAY);
    rootNode.setEffect(dropShadow);

    Scene scene = new Scene(rootNode);
    scene.setFill(Color.TRANSPARENT);
    stage.setScene(scene);
    stage.initStyle(StageStyle.TRANSPARENT);
    stage.show();
}