VBox 和 Javafx 布局问题H盒
当我运行以下命令时,我注意到节点之间的间距;我的研究表明—— 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用的是 JavaFX 1.3,该问题可能与 CtrlWindow 的首选大小有关。您可能需要使用layoutInfo来设置共同的首选尺寸,否则,首选尺寸将随着两个CtrlWindow节点的内容而改变。
例如:
当您仅设置宽度(没有绑定)时,这将重置为 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:
When you merely set the width (without a bind), this will be reset to the preferred size in the HBox layout.