Yes, the first time you call getWindow() in your code, you are not qualifying it, so I think you are actually asking for the parent Window of the ProductIntroUI instance. At the time when initialize() is executed, the BXML has been loaded, but not yet added to a parent Container. See the Bindable section here. http://pivot.apache.org/tutorials/bxml-primer.html
Adding the getWindow() call into the anonymous ButtonPressListener method should solve your problems, but I would qualify it so rather than just Window w = getWindow(); I would do Window w = arg0.getWindow(); using the supplied reference to the Button whose 'press event' you are listening for. Then the resulting Window should be the first ancestor Window of the Button which is pressed. One work around (if you ever need it) might be to add the ButtonPressListener to your PushButtons when the Window is opened. At that time the Window would be a descendant of the Display. You would do this with the windowOpened() method of a WindowStateListener. An obvious problem with this is that a Window might be opened many times, so you would need to ensure that you do not add multiple Listeners. Chris On 1 May 2011 19:50, sam <[email protected]> wrote: > This gave me clue on what happened. I was trying to test out if the > getWindow() work on initialize method of the included component > > public class ProductIntroUI extends BoxPane implements Bindable { > > @BXML > PushButton apply; > @Override > public void initialize(Map<String, Object> map, URL url, Resources > rsrcs) { > > System.out.println("Check my window is "+getWindow().toString()); > > this.apply.getButtonPressListeners().add(new ButtonPressListener() { > > @Override > public void buttonPressed(Button arg0) { > Window w = getWindow(); > ...... > do something with the window here. > ..... > } > }); > } > } > > The first call to show what is the window wasn't working. I guess because > at that time the UI is not fully loaded so it is not working yet. After > actually put the getWindow() in the listener, the window did get found. I > think the code was in the run place since the listener will be called after > the whole UI was loaded the window was assigned at the moment the listener > got called > ------------------------------ > View this message in context: Re: Dynamically adding components to a > boxpane and ID already used > error<http://apache-pivot-users.399431.n3.nabble.com/Dynamically-adding-components-to-a-boxpane-and-ID-already-used-error-tp2885412p2886147.html> > > Sent from the Apache Pivot - Users mailing list > archive<http://apache-pivot-users.399431.n3.nabble.com/>at Nabble.com. >
