最后,正如你所见到的,label和TextField被赋值为GroupPanel的elements属性。从label和TextField的声明可以看出,它们的row和column也被相应地赋值。
深入学习JavaFX脚本语言(面向Swing程序员) ---(上)(11)
时间:2011-04-19
Button(按钮)
JavaFX Button类封装了Swing的JButton组件。为了讲解如何使用Button,让我们从Swing教程中重建一个简单的示例:
class ButtonDemoModel {
attribute buttonEnabled: Boolean;
}
var model = ButtonDemoModel {
buttonEnabled: true
};
Frame {
title: "ButtonDemo"
content: FlowPanel {
content:
[Button {
text: "Disable middle button"
verticalTextPosition: CENTER
horizontalTextPosition: LEADING
icon: Image {
url: "http://java.sun.com/docs/books/tutorial/uiswing/examples/components/ButtonDemoProject/src/components/images/right.gif"
}
mnemonic: D
toolTipText: "Click this button to disable the middle button"
enabled: bind model.buttonEnabled
action: operation() {
model.buttonEnabled = false;
}
},
Button {
text: "Middle button"
icon: Image {
url: "http://java.sun.com/docs/books/tutorial/uiswing/examples/components/ButtonDemoProject/src/components/images/middle.gif"
}
verticalTextPosition: BOTTOM
horizontalTextPosition: CENTER
mnemonic: M
toolTipText: "This middle button does nothing when you click it."
enabled: bind model.buttonEnabled
},
Button {
text: "Enable middle button"
icon: Image {
url: "http://java.sun.com/docs/books/tutorial/uiswing/examples/components/ButtonDemoProject/src/components/images/left.gif"
}
mnemonic: E
toolTipText: "Click this button to enable the middle button"
action: operation() {
model.buttonEnabled = true;
}
enabled: bind not model.buttonEnabled
}]
}
visible: true
}
深入学习JavaFX脚本语言(面向Swing程序员) ---(上)(12)
时间:2011-04-19
点击左侧按钮后,程序出现以下变化:
示例程序中共有三个button,其中每个button的enabled属性都绑定到模型对象的buttonEnabled属性。当你通过触发左侧和右侧按钮的action修改此属性时,这三个button的状态都将发生变化。
我们通过将Image对象赋值给button的icon属性为按钮增添了图片。
JavaFX Image对象具有一个url属性,你可以将一个包含了 |