Apache Pivot: Swapping pane visibility

84 Views Asked by At

I'm having a problem hiding one pane and showing another in my Apache Pivot app. In my BXML file I have two BoxPanes in a window. Pane 1 starts visible and pane 2 starts hidden:

<BoxPane bxml:id="pane1" orientation="vertical" styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
  <Label text="Pane 1"/>
  <PushButton bxml:id="startButton" buttonData="Start"/>
</BoxPane>

<BoxPane bxml:id="pane2" orientation="vertical" visible="false" styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
  <Label text="Pane 2"/>
</BoxPane>

And I have a listener added to the button that should make pane 1 hidden and pane 2 visible:

@BXML private PushButton startButton = null;
@BXML private BoxPane pane1 = null;
@BXML private BoxPane pane2 = null;

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources)
{
  startButton.getButtonPressListeners().add(new ButtonPressListener()
  {
    @Override
    public void buttonPressed(Button button)
    {
      start();
    }
  });

}

private void start()
{
  pane1.setVisible(false);
  pane2.setVisible(true);
}

When I click the button though, pane 1 is hidden and pane 2 never shows up. Same thing happens when I reverse the order of the statements in start().

Interestingly enough, when I comment out pane1.setVisible(false), then pane 2 does show up when I click the button.

This is my first Pivot app, so maybe there's some fancy container that does what I want to do in a better way, but I'd still like to know what is going on here. What I'm trying to do seems pretty simple, and I'm sort of baffled why it doesn't work.

1

There are 1 best solutions below

4
rwhitcomb On

You might want to try using a CardPane to switch between your two views. The tutorial on that is here: http://pivot.apache.org/tutorials/card-panes.html The basic idea is to have the CardPane "host" your two BoxPanes, something like this:

<CardPane bxml:id="cardPane">
    <BoxPane bxml:id="pane1" ...>
        <Label text="Pane 1"/>
        ...
    </BoxPane>
    <BoxPane bxml:id="pane2" ...>
        <Label text="Pane 2"/>
    </BoxPane>
</CardPane>

Make both BoxPanes visible. Then when you want to change between them, use cardPane.setSelectedIndex(...);