VBox 和 Javafx 布局问题H盒

发布于 2024-09-03 13:40:22 字数 2621 浏览 2 评论 0原文

当我运行以下命令时,我注意到节点之间的间距;我的研究表明—— 1)如果我不通过setwininfo向win1添加任何文本,那么就没有问题。 2)当我将此代码包含在较大的应用程序中,并且从其他地方收到按钮单击时,间距会神秘地得到纠正。 3)我尝试绑定win1 & win2 节点到场景的内容 - 但没有运气。

def 大型机:整数 = 250; def mainframeh : 整数 = 500;

class CtrlWindow extends CustomNode {

var wininfo : String;
var fsize : Integer;
var width : Integer;

public function setWinInfo(info : String) {
    wininfo = info;
}

override protected function create () : Node {
    var win = Group {
                                    content: [
                                         VBox {
                                                content: [
                                                    Text {
                                                            font : Font {
                                                                    size: fsize
                                                            }

                                                            content : bind wininfo

                                                            textAlignment : TextAlignment.CENTER  // did not work
                                                    }
                                                ]
                                        }

                                        Rectangle {
                                                width: width, height: 25
                                                fill: Color.TRANSPARENT
                                                strokeWidth : 2
                                                stroke : Color.SILVER
                                        }

                                    ]
                            }

    return win;
}

}

public function run(args : String[]) {

var win1 = CtrlWindow{fsize:14, width:mainframew}; var win2 = CtrlWindow{fsize:14, 宽度:mainframew};

win1.setWinInfo("这些节点之间的间距"); win2.setWinInfo("收到事件后自行更正");

阶段 {

title : "MyApp"
scene: Scene {
    width: mainframew
    height: mainframeh
    content: [
                        VBox {
                               spacing: 0
                               content: [
                                            HBox {
                                                    content: win1
                                            }

                                            HBox {
                                                    content: win2
                                            }
                                ]
                        }
            ]
}
}

When I run the following, I noticed spacing between nodes; My research revealed that -
1) If I do not add any text to win1 via setwininfo, then there is no problem.
2) When I include this code in a larger app, and when a button click is reveived from some where else, mysteriously the spacing gets corrected.
3) I tried binding the win1 & win2 nodes to content of scene - but no luck.

def mainframew : Integer = 250;
def mainframeh : Integer = 500;

class CtrlWindow extends CustomNode {

var wininfo : String;
var fsize : Integer;
var width : Integer;

public function setWinInfo(info : String) {
    wininfo = info;
}

override protected function create () : Node {
    var win = Group {
                                    content: [
                                         VBox {
                                                content: [
                                                    Text {
                                                            font : Font {
                                                                    size: fsize
                                                            }

                                                            content : bind wininfo

                                                            textAlignment : TextAlignment.CENTER  // did not work
                                                    }
                                                ]
                                        }

                                        Rectangle {
                                                width: width, height: 25
                                                fill: Color.TRANSPARENT
                                                strokeWidth : 2
                                                stroke : Color.SILVER
                                        }

                                    ]
                            }

    return win;
}

}

public function run(args : String[]) {

var win1 = CtrlWindow{fsize:14, width:mainframew};
var win2 = CtrlWindow{fsize:14, width:mainframew};

win1.setWinInfo("The spacing between these nodes");
win2.setWinInfo("corrects itself after receiving an event");

Stage {

title : "MyApp"
scene: Scene {
    width: mainframew
    height: mainframeh
    content: [
                        VBox {
                               spacing: 0
                               content: [
                                            HBox {
                                                    content: win1
                                            }

                                            HBox {
                                                    content: win2
                                            }
                                ]
                        }
            ]
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流云如水 2024-09-10 13:40:22

假设您使用的是 JavaFX 1.3,该问题可能与 CtrlWindow 的首选大小有关。您可能需要使用layoutInfo来设置共同的首选尺寸,否则,首选尺寸将随着两个CtrlWindow节点的内容而改变。

例如:

win1 = CtrlWindow{
        fsize:14
        layoutInfo : LayoutInfo { width: mainframew, minHeight: 50 }
   }

当您仅设置宽度(没有绑定)时,这将重置为 HBox 布局中的首选大小。

Assuming you are using JavaFX 1.3, the issue may be related to the preferred sizes of the CtrlWindow. You may want to use a layoutInfo to set a common preferred size, otherwise, the preferred size will change with the content of the two CtrlWindow nodes.

Something like:

win1 = CtrlWindow{
        fsize:14
        layoutInfo : LayoutInfo { width: mainframew, minHeight: 50 }
   }

When you merely set the width (without a bind), this will be reset to the preferred size in the HBox layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文