简体   繁体   中英

How to access Boolean flag into remote Java Class

I'm working on a JavaFX application which will have several tab panes which I want to set to visible or hidden using check box which will send boolean flag to render or not to render the component.

Check box

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!");
        }
    });

Tab pane which will listen for the boolean property:

public boolean renderTab;

public boolean isRenderTab()
{
    return renderTab;
}

public void setRenderTab(boolean renderTab)
{
    this.renderTab = renderTab;
}

tabPane.setVisible(renderTab);

The check box and the tab pane are isolated into different Java Classes. I need to send the value of the flag every time when I check or uncheck the flag. Can you tell me how I can send the flag using getter and setter?

EDIT

I tested this code:

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!");
            }
        });

and

public boolean renderTab;

    public boolean isRenderTab()
    {
        return renderTab;
    }

    public void setRenderTab(boolean renderTab)
    {
        this.renderTab = renderTab;
    }

But it's not working when I switch the checkbox.

No.

Inorder to get that eithr you need to have a intance or you need to create new intance there.

If you create a new object there it will create a fresh intance,which doesnt helps you any more..

I guess the only way you have is to Make the renderTab as a static field and access there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM