5 Replies Latest reply: Apr 3, 2013 1:51 PM by jsmith RSS

    javafx2.0 failed to invoke changelistener

    905240
      Llistener(iconifiedProperty) can not be invoke correctly after set stage`s mode as "StageStyle.TRANSPARENT".
      the listener not be invoke after user click taskbar to Deiconified the window.

      who can help me?

      primaryStage.initStyle(StageStyle.TRANSPARENT);
      ..... ......
      primaryStage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {

                     @Override
                     public void changed(ObservableValue<? extends Boolean> arg0,
                               Boolean arg1, Boolean arg2) {
                          // TODO Auto-generated method stub
                          System.out.println("arg0 =" + arg0);
                          System.out.println("arg1 =" + arg1);
                          System.out.println("arg2 =" + arg2);
                     }
                });
        • 1. Re: javafx2.0 failed to invoke changelistener
          nlorain-Oracle
          make sure you file a bug on Jira http://javafx-jira.kenai.com/
          • 2. Re: javafx2.0 failed to invoke changelistener
            SlashWang
            Has this problem already solved? In which version, javaFX 2.2.7? I found this problem in 2.2.3 again.
            • 3. Re: javafx2.0 failed to invoke changelistener
              shakir.gusaroff
              Slash Wang wrote:
              Has this problem already solved? In which version, javaFX 2.2.7? I found this problem in 2.2.3 again.
              If you delete the following code
              primaryStage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {
              
              @Override
              public void changed(ObservableValue<? extends Boolean> arg0,
              Boolean arg1, Boolean arg2) {
              // TODO Auto-generated method stub
              System.out.println("arg0 =" + arg0);
              System.out.println("arg1 =" + arg1);
              System.out.println("arg2 =" + arg2);
              }
              });
              you still get the same error with the following code:
              primaryStage.show();
              primaryStage.initStyle(StageStyle.TRANSPARENT);
              .

              The error message is
               Exception in Application start method
              java.lang.reflect.InvocationTargetException
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                   at java.lang.reflect.Method.invoke(Method.java:601)
                   at com.javafx.main.Main.launchApp(Main.java:642)
                   at com.javafx.main.Main.main(Main.java:805)
              Caused by: java.lang.RuntimeException: Exception in Application start method
                   at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
                   at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
                   at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
                   at java.lang.Thread.run(Thread.java:722)
              *Caused by: java.lang.IllegalStateException: Cannot set style once stage has been set visible*
              The following looks OK.
               primaryStage.initStyle(StageStyle.TRANSPARENT);
               primaryStage.show();
              
                
              I am not sure that it is a bug. If you think it is a bug, you have to file a bug
              on Jira http://javafx-jira.kenai.com/
              • 4. Re: javafx2.0 failed to invoke changelistener
                jsmith
                Stage init* methods are designed to be called before a show method - that is why they have init prefixes as opposed to set prefixes.
                So the situation in shakir's post is not a bug.
                Specifically the following code is illegal:
                primaryStage.show();
                primaryStage.initStyle(StageStyle.TRANSPARENT);
                • 5. Re: javafx2.0 failed to invoke changelistener
                  jsmith
                  Has this problem already solved? In which version, javaFX 2.2.7? I found this problem in 2.2.3 again.
                  I tried the following application in JavaFX 8b81 and it worked fine, with the iconified property changelistener being fired as expected when the window was iconified or deiconified:
                  import javafx.application.*;
                  import javafx.beans.value.*;
                  import javafx.event.*;
                  import javafx.geometry.Pos;
                  import javafx.scene.Scene;
                  import javafx.scene.control.Button;
                  import javafx.scene.layout.*;
                  import javafx.scene.paint.Color;
                  import javafx.stage.*;
                   
                  public class StageIconification extends Application {
                    @Override public void start(final Stage stage) {
                      final Button iconify = new Button("_");
                      iconify.setStyle("-fx-base: beige; -fx-font-weight: bold;");
                      iconify.setOnAction(new EventHandler<ActionEvent>() {
                        @Override public void handle(ActionEvent t) {
                          stage.setIconified(true);
                        }
                      });
                      stage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {
                        @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean oldIconified, Boolean iconified) {
                          System.out.println("was iconified =>" + oldIconified);
                          System.out.println("is  iconified =>" + iconified);
                        }
                      });
                      
                      final Button maximize = new Button("+");
                      maximize.setStyle("-fx-base: beige; -fx-font-weight: bold;");
                      maximize.setOnAction(new EventHandler<ActionEvent>() {
                        @Override public void handle(ActionEvent t) {
                          if ("+".equals(maximize.getText())) {
                            maximize.setText("-");
                            stage.setMaximized(true);
                          } else {
                            maximize.setText("+");
                            stage.setMaximized(false);
                          }  
                        }
                      });
                      
                      final Button close   = new Button("X");
                      close.setStyle("-fx-base: salmon; -fx-font-weight: bold;");
                      close.setOnAction(new EventHandler<ActionEvent>() {
                        @Override public void handle(ActionEvent t) {
                          stage.close();
                        }
                      });
                      
                      final HBox windowControls = new HBox(10);
                      windowControls.getChildren().setAll(
                        iconify,
                        maximize,
                        close      
                      );
                      windowControls.setMaxSize(HBox.USE_PREF_SIZE, HBox.USE_PREF_SIZE);
                      windowControls.setStyle("-fx-padding: 30;");
                      
                      StackPane layout = new StackPane();
                      layout.getChildren().addAll(windowControls);
                      StackPane.setAlignment(windowControls, Pos.TOP_RIGHT);
                      
                      Scene scene = new Scene(layout);
                      scene.setFill(Color.web("coral", 0.6));
                      stage.setScene(scene);
                      
                      stage.initStyle(StageStyle.TRANSPARENT);
                  
                      stage.show();
                    }
                  
                    public static void main(String[] args) { launch(args); }
                  }