Css 如何在JavaFX中实现边界的软圆形效果

Css 如何在JavaFX中实现边界的软圆形效果,css,javafx,Css,Javafx,我有一个节点的通用边框,我想在JavaFX中使边框看起来像这样的图像(CSS和代码方式): 有人能帮我吗 提前感谢您应该使用框阴影添加带有边框和边框半径的软圆形效果 border: 1px solid #888888; box-shadow: 1px 1px 2px #888888; border-radius: 25px; 舞台的主要课程 public class SpiderMan extends Application { public static void main(String

我有一个节点的通用边框,我想在JavaFX中使边框看起来像这样的图像(CSS和代码方式):

有人能帮我吗


提前感谢

您应该使用框阴影添加带有边框和边框半径的软圆形效果

border: 1px solid #888888;
box-shadow: 1px 1px 2px #888888;
border-radius: 25px;

舞台的主要课程

public class SpiderMan extends Application {

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage stage) throws IOException {
    FXMLLoader loader = new FXMLLoader(
        getClass().getResource(
            "SpiderMan.fxml"
        )
    );
    loader.setController(new clipRound());

    Pane batman = loader.load();

    stage.setTitle("Where's Spider man Round image?");
    stage.setScene(new Scene(batman));
    stage.show();
}
}

圆形图像类视图

 class clipRound {
    @FXML
    private ImageView imageView;

    @FXML
    public void initialize() {
        // set a clip to apply rounded border to the original image.
        Rectangle clip = new Rectangle(
            imageView.getFitWidth(), imageView.getFitHeight()
        );
        clip.setArcWidth(20); the radius Arch
        clip.setArcHeight(20); the radius Arch
        imageView.setClip(clip);

        // snapshot the rounded image.
        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage image = imageView.snapshot(parameters, null);

        // remove the rounding clip so that our effect can show through.
        imageView.setClip(null);

        // apply a shadow effect.
        imageView.setEffect(new DropShadow(20, Color.BLACK));

        // store the rounded image in the imageView.
        imageView.setImage(image);
    }
}
圆形图像FXML视图“SpiderMan.FXML”



谢谢您的帮助,但我需要一些与javaFX类似的东西,这些是正常的CSS规则,我需要javaFX CSS规则,以及一种通过代码实现的方法(如果可能的话)。我还编辑了我的问题,以便更好地理解这是关于javaFX的,而不是用于web开发的标准CSS。您想将边框添加到窗格中吗?或者那是一种分离器?是的,没错。我有一个通用的节点,我希望这个效果出现在该节点的底部边界上,但我认为这个答案对我没有帮助。无论如何,感谢您的尝试,我真的很欣赏看,您可以将javaFX样式添加到图像本身setStyle(边框半径:25px),但是这种类型的边框不适用于图像,它适用于javaFX中的其他控件,如HBox和StackPane,所以,您可以在StackPane中添加图像,然后在StackPane上应用您想要的内容上面的答案很难解决图像不接受边框样式的问题我再次编辑了我的问题。我希望现在已经足够清楚了
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="313.0" prefWidth="477.0" style="-fx-background-color: azure;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
    <ImageView fx:id="imageView" layoutX="29.0" layoutY="44.0" fitHeight="224.0" fitWidth="400.0" pickOnBounds="true" preserveRatio="true">
      <image>
        <Image url="http://collider.com/wp-content/uploads/lego-batman-movie-dc-super-heroes-unite-1.jpg" />
      </image>
    </ImageView>
  </children>
</AnchorPane>