4 Replies Latest reply: Mar 17, 2013 8:32 PM by KonradZuse RSS

    Set Always on Top Stage Javafx

    906778
      How to set always on top stage javafx?
      Help Me.
      Thanks.
        • 1. Re: Set Always on Top Stage Javafx
          JohnHendrikx
          This is not currently possible as far as I know.

          The closest you can get is to set fullscreen to true, and perhaps make part of your application transparent -- you will have to wait until this is added as a feature.
          • 2. Re: Set Always on Top Stage Javafx
            906778
            Thanks
            • 3. Re: Set Always on Top Stage Javafx
              921851
              I actually found a "way around" this situation. I use transparency and a popup with a change listener to the focused property and then my window is "always on top". The only problem it's kinda like a hack and generates an exception. Here's the code:
              import br.com.vieirawebstudio.util.StageHandler;
              import sun.security.util.Resources;
              import javafx.application.Application;
              import javafx.beans.value.ChangeListener;
              import javafx.beans.value.ObservableValue;
              import javafx.fxml.FXMLLoader;
              import javafx.scene.Node;
              import javafx.scene.image.Image;
              import javafx.scene.layout.HBox;
              import javafx.scene.layout.StackPane;
              import javafx.scene.paint.Color;
              import javafx.scene.shape.Rectangle;
              import javafx.stage.Popup;
              import javafx.stage.PopupBuilder;
              import javafx.stage.Screen;
              import javafx.stage.Stage;
              
              public class MainWindow extends Application {
              
                   private static Stage primaryStage;
                   private static final double WIDTH = 600.0;
                   private static final double HEIGHT = 40.0;
                   private ChangeListener<Boolean> changeListener;
                   
                   public MainWindow()
                   {
                        changeListener = new ChangeListener<Boolean>() {
              
                             @Override
                             public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) 
                             {
                                  
                                  if(!primaryStage.isFocused())
                                  {
                                       primaryStage.setIconified(false);
                                       primaryStage.requestFocus();
                                  }
                             }
                        };
                   }
                   
                   @Override
                   public void start(Stage stage) throws Exception 
                   {
                        primaryStage = StageHandler.getStage();
                        
                        StackPane root = new StackPane();
                        Rectangle frame = new Rectangle(WIDTH,HEIGHT, Color.web("#000"));
                        frame.setOpacity(0.7);
                        
                        HBox pane = FXMLLoader.load(getClass().getResource("/fxml/MainWindow.fxml"), Resources.getBundle("bundle.MainWindow"));
                        root.getChildren().add(frame);
                        root.getChildren().add(pane);
                        
                        primaryStage.getIcons().add(new Image(getClass().getResource("/icons/logo.png").toString()));
                        primaryStage.setX((Screen.getPrimary().getVisualBounds().getWidth() - WIDTH)/2);
                        primaryStage.setTitle("Netuno");
                        primaryStage.setIconified(false);
                        primaryStage.setY(0);
                        primaryStage.focusedProperty().addListener(changeListener);
                        
                        final Popup popup = getAlwaysOnTop(root);
                        primaryStage.getScene().getStylesheets().add(getClass().getResource("/css/MainWindow.css").toString());
                        popup.show(primaryStage);
                   }
                   
                   public Popup getAlwaysOnTop(Node root)
                   {
                        Popup xmlWindow = PopupBuilder
                                  .create()
                                  .content(root)
                                  .width(WIDTH)
                                  .height(HEIGHT)
                                  .x(500.0)
                                  .y(0.0)
                                  .build();
                        
                        return xmlWindow;
                   }
              }
              • 4. Re: Set Always on Top Stage Javafx
                KonradZuse
                I found something here. http://snipplr.com/view/69423/javafx-always-on-top/

                As well as this topic, but I'm curious now if there is anything planned for 8 for always on top?