pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roger and Beth Whitcomb <RogerandB...@rbwhitcomb.com>
Subject Re: Cannot config a button press listener outside the initialize method of Bindable
Date Sat, 02 Aug 2014 20:13:50 GMT
Hi, welcome to Pivot!

The short answer is, no the "initListeners" code doesn't have to be 
called directly from "initialize" -- it just has to be called from 
"somewhere" before the button is pressed.

 From your code it is not clear when/how the "MyPanelController" 
constructor would be called.  If it is ever called (from somewhere) then 
it would work.  But, my guess would be that you don't ever instantiate 
the "MyPanelController" class, or else it only gets instantiated at some 
point after the button is pressed.  So, perhaps you could share a bit 
more of your code so we can understand better.

HTH,
~Roger

On 8/2/14 12:52 PM, ninjathehunter wrote:
> 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.
>
>


Mime
View raw message