Hi

I am writing a GUI app using Pivot.

I have a panel that looks like:

public class MyPanel extends BoxPane implements Bindable {
    @BXML private PushButton myButton = null;

    @Override
    public void initialize(final Map<String, Object> namespace, URL
location, Resources resources) {
    }

    public PushButton getMyButton() {
        return myButton;
    }
}

I have another class which does this:

public class MyPanelController {
    private MyPanel myPanel;
    private Window myWindow;

    public MyPanelController(MyPanel myPanel, Window myWindow) {
        this.myPanel = myPanel;
        this.myWindow = myWindow;
        initListeners();
    }

    private void initListeners() {
        PushButton myButton = view.getMyButton();
        myButton.getButtonPressListeners().add(new ButtonPressListener(){
            @Override
            public void buttonPressed(Button button) {
                Alert.alert(MessageType.INFO, "Button Clicked!!!",
view.getFrame());
            }
        });
    }
}

With this code, when the button is clicked, the press listner code is not
executed.

However, if I put the same event listner configuration to the initialize
method inside MyPanel, it works:

public class MyPanel extends BoxPane implements Bindable {
    @BXML private PushButton myButton = null;

    @Override
    public void initialize(final Map<String, Object> namespace, URL
location, Resources resources) {
        myButton.getButtonPressListeners().add(new ButtonPressListener(){
            @Override
            public void buttonPressed(Button button) {
                Alert.alert(MessageType.INFO, "Button Clicked!!!",
view.getFrame());
            }
        });
    }

    public PushButton getMyButton() {
        return myButton;
    }
}

My question is whether the listner handling configuration must be inside the
initialize block for it to work??

Thank you very much.




--
View this message in context: 
http://apache-pivot-users.399431.n3.nabble.com/Cannot-config-a-button-press-listener-outside-the-initialize-method-of-Bindable-tp4022979.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Reply via email to