我正在开发一个 JavaFX 应用程序,该应用程序将有几个选项卡窗格,我想使用复选框将其设置为可见或隐藏,该复选框将发送布尔标志以呈现或不呈现组件。
复选框
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
将侦听布尔属性的选项卡窗格:
public boolean renderTab;
public boolean isRenderTab()
{
return renderTab;
}
public void setRenderTab(boolean renderTab)
{
this.renderTab = renderTab;
}
tabPane.setVisible(renderTab);
复选框和选项卡窗格被隔离到不同的 Java 类中。每次选中或取消选中标志时,我都需要发送标志的值。你能告诉我如何使用 getter 和 setter 发送标志吗?
编辑
我测试了这段代码:
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
boolean dcd = toolbarSubMenuNavigation.isSelected();
DataTabs nn = new DataTabs();
nn.setRenderTab(dcd);
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
和
public boolean renderTab;
public boolean isRenderTab()
{
return renderTab;
}
public void setRenderTab(boolean renderTab)
{
this.renderTab = renderTab;
}
但是当我切换复选框时它不起作用。