【发布时间】:2018-09-24 09:39:38
【问题描述】:
我在 fxml 文件中使用 CardPane 组件:
<?import com.gluonhq.charm.glisten.control.CardPane?>
<CardPane fx:id="cardList">
<Label text="label1" />
<Label text="label2" />
</CardPane>
使用我的控制器:
public class Sample extends Pane {
@FXML
private CardPane cardList;
private final String FXML_FILE = "sample.fxml";
public Sample()
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource(FXML_FILE));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try
{
fxmlLoader.load();
}
catch (IOException ioexception)
{
throw new RuntimeException(ioexception);
}
}
protected void clickItem()
{
System.out.println("The item 'x' was clicked!");
}
是否可以向 CardPane 的项目添加侦听器,以便当我单击一个项目时调用 clickItem() 方法?如何进行 ?以及如何确定点击了哪个项目?
【问题讨论】: