栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JavaFX 8-在右侧的TitledPane中添加图形

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JavaFX 8-在右侧的TitledPane中添加图形

根据OP在其已编辑问题上显示的代码,此代码解决了以下事实:在显示阶段之前,在自定义类上在侦听器上创建了标题窗格。

@Overridepublic void start(Stage primaryStage) {    Scene scene = new Scene(new StackPane(), 300, 250);    primaryStage.setScene(scene);    primaryStage.setonShown(e -> {        CustomTitledPane customTitledPane = new CustomTitledPane("Title", new StackPane(new Label("Graphic to the Right")));        scene.setRoot(customTitledPane);        customTitledPane.applyCss();        customTitledPane.layout();        // title region        Node titleRegion=customTitledPane.lookup(".title");        // padding        Insets padding=((StackPane)titleRegion).getPadding();        // image width        double graphicWidth=customTitledPane.getGraphic().getLayoutBounds().getWidth();        // arrow        double arrowWidth=titleRegion.lookup(".arrow-button").getLayoutBounds().getWidth();        // text        double labelWidth=titleRegion.lookup(".text").getLayoutBounds().getWidth();        double nodesWidth = graphicWidth+padding.getLeft()+padding.getRight()+arrowWidth+labelWidth;        customTitledPane.graphicTextGapProperty().bind(customTitledPane.widthProperty().subtract(nodesWidth));    });    primaryStage.show();}class CustomTitledPane extends TitledPane {    public CustomTitledPane(String titleText, Node node) {        super(titleText, node);        setAnimated(true);        setCollapsible(true);        ImageView img = new ImageView(new Image(getClass().getResource("unlock24.png").toExternalForm()));        img.setFitHeight(10d);        img.setPreserveRatio(true);        img.setSmooth(true);        setGraphic(img);        setContentDisplay(ContentDisplay.RIGHT);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515453.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号