BorderPane

Hi all, I am trying to make a Border Layout using BorderPane class, I have filled all Pane places exactly as technical documentations says, but my BorderPane occupied fixed area of my stage, I mean that the Pane does not resize while stage resizing, I have called some methods like autoResize(), and setAutoSizeChildren(true) on stage, root group, and border pane, but there is no effect, Anyone has any idea about solution?
Thanks for Concern.
Ahmad Elsafty

When a Group is the root node, the size of the stage is irrelevant to the Group's position and layout. When a Pane is is the root node, it is resized with the Stage. If you are unable to use the Pane as the root node, then you will have to try something else. Maybe you could try binding its width and height properties to that of the scene.

Similar Messages

  • Set BorderPane components size

    I want to set the size of the Center, Top, Left, Right and Bottom components of a BorderPane.
    http://i.stack.imgur.com/hY8i6.png
    So far I found this:
    BorderPane() mainpane = new BorderPane();
    mainPane.getBottom().prefWidth(sizeX);
    For example how I can you get the size of a Left side of a BorderPane and set the size?

    Read the Javadocs. Immediately below the image you link it says
    The top and bottom children will be resized to their preferred heights and extend the width of the borderpane. The left and right children will be resized to their preferred widths and extend the length between the top and bottom nodes. And the center node will be resized to fill the available space in the middle.
    So you need to set the preferred sizes of the controls you add to these regions. You can also retrieve the size of the same nodes once they've been added to a live scene by calling getWidth() and getHeight() on those nodes.

  • Bug or feature: BorderPane ignores reflection in sizing

    Just started to explore fx (read: complete newbie here :-), so grabbing code examples and came across one by Walter (below is a minimal extract of the fx app):
    http://weblogs.java.net/blog/ixmal/archive/2011/06/02/using-javafx-20-inside-swing-applications#comment-815938
    It's a simple Label with reflection. Problem is that the reflection is not completely visible if added to the center of a BorderPane (nor a StackPane), looks somehow translated in y direction. All okay when added to top or with a VBox/HBox/FlowPane.
    Ideas? Or in other words: what I'm missing or doing wrong ;-)
    Thanks
    Jeanette
    public class LayoutLabel extends Application {
        @Override
        public void start(Stage stage) throws Exception {
            stage.setTitle("Test JFX");
            stage.setScene(createScene());
            stage.setVisible(true);
        private Scene createScene() {
            Label label = new Label("Hello world!");
            label.setFont(new Font(24));
            label.setEffect(new Reflection());
            BorderPane pane = new BorderPane();
            pane.setCenter(label);
    //        pane.setTop(label);
    //        pane.setBottom(label);
    //        Pane pane = new StackPane();
    //        Pane pane = new FlowPane();
    //        Pane pane = new HBox();
    //        pane.getChildren().add(label);
            Scene scene = new Scene(pane);
            return scene;
        public static void main(String[] args) {
            Application.launch(args);
    }

    Hi,
    I did not quiet understand what you mean. It looks completely visible for me.
    You did not set scene width and height so maybe that is reason why it was not visible.
    This code works for me:
    package playground;
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.effect.Reflection;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    public class LayoutLabel extends Application {
        @Override
        public void start(Stage stage) throws Exception {
            stage.setTitle("Test JFX");
            stage.setScene(createScene());
            stage.setVisible(true);
        private Scene createScene() {
            Label label = new Label("Hello world!");
            label.setFont(new Font(24));
            Reflection reflection = new Reflection();
            reflection.setFraction(1.0);
            reflection.setBottomOpacity(1.0);
            reflection.setTopOffset(0.0);
            label.setEffect(reflection);
    //        Group pane = new Group();
            BorderPane pane = new BorderPane();
            pane.setCenter(label);
    //        pane.setTop(label);
    //        pane.setBottom(label);
    //        Pane pane = new StackPane();
    //        Pane pane = new FlowPane();
    //        Pane pane = new HBox();
    //        pane.getChildren().add(label);
            Scene scene = new Scene(pane, 200,200); // changes to 200 200 maybe that is reason why it does not show
            return scene;
        public static void main(String[] args) {
            Application.launch(args);
    }

  • Strange Behavior with Rectangle in BorderPane

    I'm creating a Rectangle, filling it with a gradient, and setting it as the top component of a BorderPane. Then, when the BorderPane expands I also want the Rectangle to expand. And when the BorderPane shrinks I want the rectangle to shrink. The code looks like:
    BorderPane mainLayout = new BorderPane();
            VBox.setVgrow(mainLayout, Priority.ALWAYS);
            getChildren().add(mainLayout);
            Text title = new Text("New Entry");
            title.setFont(Font.font(title.getFont().getName(), title.getFont().getSize() * 1.6));
            HBox titlePanel = new HBox();
            titlePanel.setAlignment(Pos.CENTER);
            //titlePanel.getChildren().add(title);   
            // TODO: How to make this rectangle grow to always fill the form title?
            Stop[] stops = new Stop[] { new Stop(0, Color.STEELBLUE), new Stop(1, Color.WHITE)};
            LinearGradient gradient = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops);
            final Rectangle r = new Rectangle() {
                @Override
                public boolean isResizable() {
                    return true;
            setFillHeight(true);
            mainLayout.widthProperty().addListener(
                    new ChangeListener<Number>() {
                        @Override
                        public void changed(
                                ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                            System.out.println("Setting width to " + newValue);
                            // r.setWidth(newValue.intValue());
            r.widthProperty().bind(widthProperty());
            r.setHeight(100);
            r.setFill(gradient);
            titlePanel.getChildren().add(r);
            mainLayout.setTop(titlePanel);----
    Strangely enough this code works if the BorderPane is expanded to a greater size than it was previously. In this case the ChangeListener will be invoked and widthProperty will But if the BorderPane shrinks then nothing shrinks and the ChangeListener is never called. Is this a bug? Why would the BorderPane be able to expand but to never shrink?
    Any help appreciated, thanks.
    Edited by: ocean on Aug 27, 2011 9:22 AM
    Edited by: ocean on Aug 27, 2011 9:22 AM

    Not sure why, but I managed to fix this issue. The BorderPane in the code snippet above was itself embedded inside a HBox that was itself being embedded inside the center of another BorderPane. I removed the titlepanel from the embedded BorderPane and put it in the top-level BorderPane. There I was able to get the Rectangle to expand and contract as the window was received. This seems to be another "nesting thing" with JavaFX and it's not the first such issue I've run into, particularly with respect to resize behavior. I wish the documentation could be updated so that it's clear how the different nodes, particularly layouts, behave with respect to resizing. Thanks.

  • External FXML file within AnchorPane/BorderPane/Pane

    I need to load a FXML file into a panel (AnchorPane, BorderPane, Pane, etc) but I had some problems.
    Initially I tried to load my external FXML file within AnchorPane the following manner:
    package signa;
    import java.net.URL;
    import java.util.ResourceBundle;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.fxml.Initializable;
    import javafx.scene.Parent;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.HBox;
    public class Estructura_GeneralController {
        /*ignore this section
        @FXML Button modalidadButton;
        @FXML Button closeButton;
        @FXML Button chatButton;
        @FXML Button helpButton;
        @FXML HBox herramientas;
        @FXML Button latLonBtn;
        @FXML Button utmBtn;
        @FXML AnchorPane paneles;
        @FXML Button agregarUnidadBtn;
        @FXML Button derrotasBtn;
        @FXML Button editarUnidadBtn;
        @FXML Button marcadoresBtn;
        @FXML Button organizacionTareasBtn;
        @FXML Button nuevoPlanBtn;
        @FXML Button patronesBtn;
        @FXML Parent agregarUnidadPanel;
        @FXML Parent derrotasPanel;
        @FXML Parent editarUnidadPanel;
        @FXML Parent marcadoresPanel;
        @FXML Parent organizacionTareasPanel;
        @FXML Parent nuevoPlanPanel;
        @FXML Parent patronesPanel;
        public void switchPane(ActionEvent event) {
              Object eventSource = event.getSource();
              if (eventSource == agregarUnidadBtn) {
    //               paneles.setCenter(agregarUnidadPanel);//.addAll(pane1);
                            paneles.setLeftAnchor(agregarUnidadPanel, null);
                            paneles.getChildren().addAll(agregarUnidadPanel);
              } else if (eventSource == derrotasBtn) {
                   paneles.setLeftAnchor(derrotasPanel, null);
                            paneles.getChildren().addAll(derrotasPanel);
              } else if (eventSource == editarUnidadBtn) {
                   paneles.setLeftAnchor(editarUnidadPanel, null);
                            paneles.getChildren().addAll(editarUnidadPanel);
              } else if (eventSource == marcadoresBtn) {
                   paneles.setLeftAnchor(marcadoresPanel, null);
                            paneles.getChildren().addAll(marcadoresPanel);
              }else if (eventSource == organizacionTareasBtn) {
                   paneles.setLeftAnchor(organizacionTareasPanel, null);
                            paneles.getChildren().addAll(organizacionTareasPanel);
              }else if (eventSource == nuevoPlanBtn) {
                   paneles.setLeftAnchor(nuevoPlanPanel, null);
                            paneles.getChildren().addAll(nuevoPlanPanel);
              }else if (eventSource == patronesBtn) {
                   paneles.setLeftAnchor(patronesPanel, null);
                            paneles.getChildren().addAll(patronesPanel);
    }Now, in the FXML file:
    //All this is within a AnchorPane
                      <AnchorPane fx:id="paneles" minHeight="0.0" minWidth="0.0" styleClass="anchorpane">
                      <prefHeight>
                        <Long fx:value="851" />
                      </prefHeight>
                      <prefWidth>
                        <Long fx:value="426" />
                      </prefWidth>
                      <stylesheets>
                        <URL value="@SIGNA.css" />
                      </stylesheets>
                      <fx:define>
                             <fx:include source="Panel_AgregarUnidades.fxml" fx:id="agregarUnidadPanel"/>
                      </fx:define>
                      <fx:define>
                             <fx:include source="Panel_Derrotas.fxml" fx:id="derrotasPanel"/>
                      </fx:define>
                      <fx:define>
                             <fx:include source="Panel_EditarUnidades.fxml" fx:id="editarUnidadPanel"/>
                      </fx:define>
                      <fx:define>
                             <fx:include source="Panel_Marcadores.fxml" fx:id="marcadoresPanel"/>
                      </fx:define>
                      <fx:define>
                            <fx:include source="Panel_OrganizacionTareas.fxml" fx:id="organizacionTareasPanel"/>
                      </fx:define>
                      <fx:define>
                            <fx:include source="Panel_NuevoPlan.fxml" fx:id="nuevoPlanPanel"/>
                      </fx:define>
                      <fx:define>
                            <fx:include source="Panel_PatronesPanel.fxml" fx:id="patronesPanel"/>
                      </fx:define>
                    </AnchorPane>
                    //With these buttons try to load the external panels
                    <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" styleClass="anchorpane, Vbox">
                      <children>
                        <Button fx:id="agregarUnidadBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="12.0" mnemonicParsing="false" onAction="#switchPane" prefWidth="88.0" text="${'Agregar' + '\n' + 'Unidades'}" />
                        <Button id="derrotasPanel" fx:id="derrotasBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="57.0" mnemonicParsing="false" onAction="#switchPane" prefHeight="37.0" prefWidth="88.0" text="Derrotas" />
                        <Button fx:id="editarUnidadBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="102.0" mnemonicParsing="false" onAction="#switchPane" prefWidth="88.0" text="${'Editar' + '\n' + 'Unidades'}" />
                        <Button fx:id="marcadoresBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="147.0" mnemonicParsing="false" onAction="#switchPane" prefHeight="37.0" prefWidth="88.0" text="Marcadores" />
                        <Button fx:id="organizacionTareasBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="192.0" mnemonicParsing="false" onAction="#switchPane" prefWidth="88.0" text="${'Organización' + '\n' + 'de Tareas'}" />
                        <Button fx:id="nuevoPlanBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="237.0" mnemonicParsing="false" onAction="#switchPane" prefWidth="88.0" text="${'Nuevo' + '\n' + 'Plan'}" />
                        <Button fx:id="patronesBtn" contentDisplay="CENTER" layoutX="5.0" layoutY="282.0" mnemonicParsing="false" onAction="#switchPane" prefHeight="37.0" prefWidth="88.0" text="Patrones" />
                      </children>In this way I managed to load the external FXML file but but gives me an exception.
    WARNING: com.sun.javafx.css.StyleHelper calculateValue caught:
    java.lang.IllegalArgumentException: No enum constant javafx.geometry.Pos.left
    furthermore if I press a button pressed previously, I have another problem of exception.
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException*
    Caused by: java.lang.reflect.InvocationTargetException
    *Caused by: java.lang.IllegalArgumentException: Children: duplicate children added: parent = AnchorPane[id=paneles, styleClass=anchorpane]*
    I also tried a slightly changing BordePane controller code:
    public void switchPane(ActionEvent event) {
              Object eventSource = event.getSource();
              if (eventSource == agregarUnidadBtn) {
                   paneles.setCenter(agregarUnidadPanel);
                            paneles.getChildren().addAll(agregarUnidadPanel);
              } Now obviously the variable "paneles" is a BorderPane.
    however the result is the same only without having the problem of the second exception I had with the AnchorPane
    I attached a picture to have some idea
    Thank you very much any help and I ask an apology for the bad English.
    http://img42.imageshack.us/img42/5770/panelssigna.png
    http://img17.imageshack.us/img17/117/examplepanelagregarunid.png
    Edited by: biochemistry43 on 11/12/2012 12:55 PM

    This is the only part in my CSS file where the word left
    .table-view .column-header .label{
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
        -fx-text-fill: white;
        -fx-alignment: left;
    }This is the only part in my CSS file where the word left
    If I suppress the error goes away which is great and I am happy but ... I do not understand why ... Why does that matter?
    If I put the word left (without quotes) returns the error and if I put it back (with quotes), however get the error.
    This is all my CSS code:
    .theme {
            master-color: gray;
        -fx-border-width: 1px;
    /*    -fx-border-color: rgb(30,30,30);*/
        -fx-background-color: rgb(50,50,50);
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
    *.split-pane {
        -fx-padding: 0;
        -fx-border-width: 0;
    *.anchorpane {
        -fx-background-color: rgb(50,50,50);
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
        /*-fx-background-insets: 0,1,4,5,6;*/
        -fx-background-radius: 9,8,5,4,3;   
        -fx-padding: 3 11 3 11;
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
        -fx-border: 1px;
        -fx-border-color: rgb(30,30,30);
    .borderpane {
        -fx-background-color: rgb(50,50,50);
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.4) , 5, 0.0 , 0 , 1 );
        /*-fx-background-insets: 0,1,4,5,6;*/
        -fx-background-radius: 9,8,5,4,3;   
        -fx-padding: 3 11 3 11;
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
        -fx-border: 1px;
        -fx-border-color: rgb(30,30,30);
    /*Layouts menores*/
    *.Hbox {
    -fx-background-color: rgb(80,80,80);
    -fx-background-radius: 10px;
    -fx-border-width: 2px;
    -fx-border-color: rgb(110,110,110);
    -fx-border-radius: 10px;
    -fx-padding: 5px;
    -fx-spacing: 5px;
    *.Vbox {
    -fx-background-color: rgb(80,80,80);
    -fx-background-radius: 10px;
    -fx-border-width: 2px;
    -fx-border-color: rgb(110,110,110);
    -fx-border-radius: 10px;
    -fx-padding: 5px;
    .frame {
        -fx-background-color: rgb(80, 80, 80);
        -fx-padding: 2px;
        -fx-border-width: 2px;
        -fx-border-color: rgb(110, 110, 110) ;
    .display-frame {
        -fx-border-color: rgb(230, 230, 230);
        -fx-border-radius: 10px;
        -fx-border-width: 2px;
        -fx-padding: 2px;
        -fx-background-color: linear-gradient(#505050 5%, #505050 60%, #404040 80%);
    /*botones*/
    .toggle-button{
        min-width: 25px;
         max-width: 80px;
         min-height: 18px;
         max-height: 19px;
        -fx-border-radius:10px;
        -fx-padding: 5; /*espacio entre los bordes del boton*/
        -fx-background-radius: 10px;
        -fx-background-color:
            #090a0c,
            linear-gradient(#404040 0%, #404040 5%, #303030 60%)
            radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
        -fx-text-fill: white ;
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
    .toggle-button:hover {
        -fx-effect: dropshadow( three-pass-box , #808080  , 5, 0.6 , 0 , 0);
    .toggle-button:selected {
        -fx-background-color: rgb(130,130,130);
        -fx-text-fill: white;
        -fx-border-insets: 0;
        -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    /*.menu-item {
        -fx-background-color: gray;
    .button {
         min-width: 25px;
         max-width: 80px;
         min-height: 18px;
         max-height: 19px;
        -fx-border-radius:10px;
        -fx-padding: 5; /*espacio entre los bordes del boton*/
        -fx-background-radius: 10px;
        -fx-background-color:
            #090a0c,
            linear-gradient(#404040 0%, #404040 5%, #303030 60%)
            radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
        -fx-text-fill: white ;
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
    .button:hover {
       -fx-effect: dropshadow( three-pass-box , #808080  , 5, 0.6 , 0 , 0);
    .button:pressed {
    /*    -fx-border-color:rgb(0, 225, 255);*/
    /*    -fx-border-width: 2px;*/
        -fx-background-color: rgb(130,130,130);
        -fx-text-fill: white;
        -fx-border-insets: 0;
        -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    #nvoPlanBtn:focused, #openPlanBtn:focused, #savePlanBtn:focused, #closePlanBtn:focused,
    #addUnitsBtn:focused, #editUnitsBtn:focused, #tareasBtn:focused, #marcadoresBtn:focused, #derrotasBtn:focused,
    #patronesBtn:focused, #metOCBtn:focused {
        -fx-background-color: rgb(130,130,130);
        -fx-text-fill: white;
        -fx-border-insets: 0;
        -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    .etiquetas-botones {
        -fx-text-fill: white;
        -fx-font-style: italic;
    #newButton:pressed, #openButton:pressed, #saveButton:pressed, #saveAsButton:pressed, #layersButton:pressed,
    #zoomInButton:pressed, #zoomOutButton:pressed, #zoomMexicoButton:pressed, #zoomMundoButton:pressed, #zoomBoxButton:pressed,
    #panViewButton:pressed, #selectButton:pressed, #pointButton:pressed, #poliLineButton:pressed{
        -fx-background-color: rgb(130,130,130);
        -fx-text-fill: white;
        -fx-border-insets: 0;
        -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    .split-pane .split-pane-divider {
        -fx-background-color: rgb(50,50,50);
        -fx-border-color: rgb(50,50,50);
        -fx-minor-tick-visible: false;
    #newButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/file_new.png");
    /*    -fx-background-color: transparent;*/
    #openButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/abrir.png");
    /*    -fx-background-color: transparent;*/
    #saveButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/guardar.png");
    /*    -fx-background-color: transparent;*/
    #saveAsButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/guardar_como.png");
    /*    -fx-background-color: transparent;*/
    #layersButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/Layers.png");
    /*    -fx-background-color: transparent;*/
    #zoomInButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/Zoom_In.png");
    /*    -fx-background-color: transparent;*/
    #zoomOutButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/Zoom_Out.png");
    /*    -fx-background-color: transparent;*/
    #zoomMexicoButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/mexico.png");
    /*    -fx-background-color: transparent;*/
    #zoomMundoButton{
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/mundo.png");
    /*    -fx-background-color: transparent;*/
    #zoomBoxButton{
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/zoom-box.png");
    /*    -fx-background-color: transparent;*/
    #panViewButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/pan.png");
    /*    -fx-background-color: transparent;*/
    #selectButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/pointer.png");
    /*    -fx-background-color: transparent;*/
    #pointButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/punto.png");
    /*    -fx-background-color: transparent;*/
    #poliLineButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/polilinea.png");
    /*    -fx-background-color: transparent;*/
    #shapeButton {
    /*    -fx-text-fill: null;*/
        -fx-graphic: url("../signa/img/poligono.png");
    /*    -fx-background-color: transparent;*/
    #closeButton {
        -fx-text-fill: null;
        -fx-graphic: url("../signa/img/close.png");
        -fx-background-color: transparent;
    #closeButton:hover{
        -fx-effect: dropshadow( three-pass-box , red  , 5, 0.6 , 0 , 0);
    #closeButton:pressed{
        -fx-effect: dropshadow( three-pass-box , aqua  , 5, 0.6 , 0 , 0);
    #helpButton {
        -fx-text-fill: null;
        -fx-graphic: url("../signa/img/Help_Icon.png");
        -fx-background-color: transparent;
    #chatButton {
        -fx-text-fill: null;
        -fx-graphic: url("../signa/img/chat.png");
        -fx-background-color: transparent;
    /*.menu-button {
         min-width: 25px;
         max-width: 80px;
         min-height: 18px;
         max-height: 19px;
        -fx-text-fill:white;
        -fx-border-radius:10px;
        -fx-padding: 5; espacio entre los bordes del boton
        -fx-background-radius: 10px;
        -fx-background-color:
            #090a0c,
            linear-gradient(#404040 0%, #404040 5%, #303030 60%)
            radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
        -fx-text-fill: aliceblue;
    .menu-item:hover {
         -fx-blend-mode: darken;
    .label{
        -fx-font-weight: bold;
    .label.headPaneLabel{
        -fx-font-size:20px;
        -fx-font-family: "Calibri";
        -fx-text-fill: rgb(234,254,254);
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
    .label.contentLabel {
        -fx-font-size:11px;
        -fx-font-family:"Calibri";
        -fx-font-style: normal ;
        -fx-text-fill: rgb(234,254,254);
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);  
    .label-name {
        -fx-text-fill: rgb(0, 225, 255);
        -fx-font-size: 36px;
        -fx-font-weight: bold;
    .label-unit-station {
        -fx-text-fill: rgb(0, 225, 255);
        -fx-font-size: 17px;
        -fx-font-weight: bold;
    .label-date-timeUTC-gps {
        -fx-text-fill: rgb(0, 225, 255);
        -fx-font-size: 14px;
        -fx-font-weight: bold;
    .label-cog-sog-hdg {
        -fx-text-fill: rgb(0, 225, 255);
        -fx-font-size: 16px;
        -fx-font-weight: bold;
    .label-long-lat {
        -fx-text-fill: rgb(0, 225, 255);
        -fx-font-size: 22px;
        -fx-font-weight: bold;
    /*radiobuttons*/
    .radio-button {
        -fx-text-fill: rgb(234,254,254);
        -fx-border: transparent;
    .radio-button:pressed .dot {
        -fx-background-color: black;
    .radio-button:hover .radio {
        -fx-effect: dropshadow( three-pass-box , #00FFFF , 3, 0.0 , 0 , 1);      
    .radio-button:focused .radio{
      -fx-effect: dropshadow( three-pass-box , #00FFFF , 3, 0.0 , 0 , 1);
    .separator {
        -fx-background-color: rgb(234,254,254);
        -fx-border-style: none;
        -fx-border-width: 0px;
    .text-field {
        -fx-border-width: 1px;
        -fx-border-color: rgb(130,130,130);
        -fx-border-radius: 5px;
        -fx-background-radius: 5px;
        -fx-background-color: rgb(50,50,50);
        -fx-text-fill: white;
    .choice-box {
        -fx-border-width: 1px;
        -fx-border-color: rgb(130, 130, 130);
        -fx-border-radius: 5px;
        -fx-text-fill: white;
        -fx-background-radius: 5px;
        -fx-background-color: rgb(50,50,50);
    .table-view {
        -fx-background-color: rgb(70,70,70);
        -fx-text-fill: white;
        -fx-border-style: solid;
        -fx-border-color: transparent;
    /*    -fx-border-insets: 0 1 1 0, 0 0 0 0;*/
        -fx-border-width: 0.083333em, 0.083333em;
    .table-view .column-header{
        -fx-border-style: solid;
        -fx-border-color: rgb(130, 130, 130);
        -fx-border-radius: 5px;
        -fx-background-radius: 5px;
        -fx-border-insets: 0 1 1 0, 0 0 0 0;
        -fx-border-width: 0.083333em, 0.083333em;
    .table-view .column-header .label{
        -fx-font-size: 11px;
        -fx-font-family: "Calibri";
        -fx-text-fill: white;
    /*    -fx-alignment: "left";*/
    .table-view .column-header-background {
        -fx-background-radius: 5px;
        -fx-font-family: "Calibri";
        -fx-background-color:  rgb(50,50,50);
    .table-view .column-header-background .filler{
        -fx-background-color: rgb(50,50,50);
        -fx-border-color: rgb(50,50,50);
    .table-row-cell {
        -fx-background-color: rgb(100,100,100);
        -fx-background-insets: 0, 0 0 1 0;
        -fx-padding: 0.0em;
    .table-row-cell:selected {
        -fx-background-color: dimgrey;
        -fx-background-insets: 0, 0 0 1 0;
        -fx-padding: 0.0em;
    /*.table-cell {
        -fx-font-style: bold;
        -fx-text-fill: black;
    .table view .table-cell:selected{
        -fx-text-fill: white;
    /*.table-row-cell:odd {
        -fx-background-color: #414141;
        -fx-background-insets: 0, 0 0 1 0;
        -fx-padding: 0.0em;  0
        -fx-text-fill: white;
    .scroll-bar .track{
        -fx-background-color: rgb(130,130,130);
        -fx-border-width: 1px;
        -fx-border-color: gray;
    .scroll-bar .track:pressed{
        -fx-background-color: white;
    .scroll-bar .thumb{
        -fx-background-color:
            #090a0c,
            linear-gradient(#404040 0%, #404040 5%, #303030 60%)
            radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
    .scroll-bar .thumb:hover{
        -fx-effect: dropshadow( three-pass-box , #808080  , 5, 0.6 , 0 , 0);
    .scroll-bar .thumb:pressed{
       -fx-background-color: rgb(130,130,130);
       -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    .scroll-bar .decrement-button{
       -fx-background-color:
            #090a0c,
            linear-gradient(#404040 0%, #404040 5%, #303030 60%)
            radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
    .scroll-bar .decrement-button:hover {
          -fx-effect: dropshadow( three-pass-box , #808080  , 5, 0.6 , 0 , 0);
    .scroll-bar .decrement-button:pressed{
        -fx-background-color: rgb(130,130,130);
        -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    .scroll-bar .decrement-button .decrement-arrow{
        -fx-background-color: gray;
        -fx-border-color: transparent;
        -fx-border-width: 0px;
    .scroll-bar .decrement-button .decrement-arrow:pressed{
        -fx-background-color: white;   
    .scroll-bar .increment-button{
        -fx-background-color:
            #090a0c,
            linear-gradient(#404040 0%, #404040 5%, #303030 60%)
            radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));
        -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 3, 0.0 , 0 , 1);
    .scroll-bar .increment-button:hover{
         -fx-effect: dropshadow( three-pass-box , #808080  , 5, 0.6 , 0 , 0);
    .scroll-bar .increment-button:pressed{
        -fx-background-color: rgb(130,130,130);
        -fx-effect: dropshadow( three-pass-box , rgba(0, 225, 255,1) , 5, 0.3 , 0 , 0);
    .scroll-bar .increment-button .increment-arrow{
        -fx-background-color: gray;
        -fx-border-color: transparent;
        -fx-border-width: 0px;
    .scroll-bar .increment-button .increment-arrow:pressed{
        -fx-background-color: white;
    .scroll-pane .corner{
        -fx-background-color: transparent;
    .tab-pane{
        -fx-tab-max-height: 12pt;
    .tab-pane .tab-content-area{
       -fx-background-color: rgb(80, 80, 80);
       -fx-padding: 2px;
       -fx-border-width: 2px;
       -fx-border-color: rgb(110, 110, 110) ;
    .tab-pane .tab-header-area .tab{
        -fx-background-color: rgb(60, 60, 60);
        -fx-background-radius: 4px;
        -fx-border-width: 2px;
        -fx-border-color: #707070;
        -fx-border-radius: 4px;
        -fx-padding: 0 0 0 0;
    .tab-pane .tab-header-area .tab:hover{
        -fx-border-color:  linear-gradient(#909090 60%, #909090 5%, #909090 0%);
    .tab-pane .tab-header-area .tab:selected{
        -fx-border-color:  linear-gradient(#00FFFF 60%, #00FFFF 5%, #00FFFF 0%);
        -fx-background-color: rgb(130,130,130);
        -fx-text-fill: white;
        -fx-border-insets: 0;
    .tab-pane .tab-header-area .tab-header-background {
        -fx-background-color:transparent;
    .tab-pane .tab-header-area .tab .tab-label{
        -fx-text-fill: white;
         -fx-font-size: 11px;
        -fx-font-family: "Calibri";
        -fx-alignment: center;
    }Edited by: biochemistry43 on 13/12/2012 09:06 AM

  • Sometimes JavaFX form (BorderPane) does not show correctly

    We have a problem with a JavaFX application running on Java 7. Sometimes a form (BorderPane) does not show correctly – it seems to be transparent (i.e. content previously shown at the same place is still visible). Controls seem to be present and respond to events – e.g. we can close the form by blindly clicking the appropriate button. Once the issue happens it is persistent, i.e. next time we open the form, it behaves the same.
    We have no reproducible scenario leading to the issue. It just happens here and there – we have not been able to identify any pattern yet.
    Additional information:
    the form (BorderPane) is loaded during application start-up but it is not shown initially,
    to show the form we remove previous contents from a StackPane and add the form instead,
    to hide the form we do the reverse.
    Do you have any ideas how to diagnose the problem? Where to look first? What kind of diagnostic code could we put in the application that would help us?

    I am unaware of any such issue being reported previously.
    Without a reproducible test case, you are unlikely to get much assistance.
    Other than the creation of a minimal test case which reproduces the issue, I could not even advise how you might go about diagnosing and fixing your issue.
    There were many bug fixes implemented for Java 8.
    I advise you to upgrade your test environment to the latest Java early access release (currently Java 8u40) and test to verify if your issue replicates in that version.
    If the issue still reproduces, create a bug report which includes your test case and full environment details.

  • Changing BorderPane contraints causes component to disappear

    Hello everyone,
    I have this short snippet that is giving me a headache, don't know if it's something i'm doing wrong but the behavior seems weird to me:
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    public class MainWindow extends Application {
         public static void main(String[] args) {
              Application.launch(args);
         public void start(Stage s) {
              BorderPane workArea = new BorderPane();
              Button button = new Button(".");
              Scene scene = new Scene(workArea, 800, 600, Color.TRANSPARENT);
              s.setScene(scene);
              s.show();
              workArea.setCenter(button);
              workArea.getChildren().remove(button);
              workArea.setLeft(button);
              workArea.getChildren().remove(button);
              workArea.setCenter(button);
    }As you can see i move the same component back and forth between left and center. When you run this piece of code you'll get and empty stage.
    I have a workaround (more like a hack) but it seems that i'm lacking something, what i do in order for this to work is creating a new instance of button and remove the original from the Pane, this works ok but then i would have to copy all the properties from the original object.
    Any idea on if it's normal, why, and how to workaround this?
    Thanks
    Bruno

    Hi Bruno,
    Yea, weird this doesn't work - just ran it and got the same results as you. Strangely the following does work:
    public void start(Stage stage) throws Exception
        BorderPane workArea = new BorderPane();
        Scene scene = new Scene(workArea, 800, 600);
        stage.setScene(scene);
        stage.show();
        Button button = new Button("Test");
        workArea.setLeft(button);
        workArea.setLeft(null);
        workArea.setRight(button);
        workArea.setRight(null);
        workArea.setCenter(button);
    }So it looks like it is a problem specifically with the remove on BorderPane not doing something that the setLeft/Right/Center does. I can't see a bug for it so I would suggest raising one. The above code is painful as you would have to record where it was last added in order to remove it on the next move.
    You could also use another layout. For my money, I highly recommend MigLayout. You can do very complex layouts simply in a single pane and it handles this dynamic adding stuff well:
    public void start(Stage stage) throws Exception
        MigPane workArea = new MigPane("fill");
        Scene scene = new Scene(workArea, 800, 600);
        stage.setScene(scene);
        stage.show();
        Button button = new Button("Test");
        workArea.add(button, "left");
        workArea.getChildren().remove(button);
        workArea.add(button, "right");
        workArea.getChildren().remove(button);
        workArea.add(button, "center");
    }You need the core MigLayout library from here: http://www.miglayout.com/
    And the JFX wrapper is here: http://java.net/projects/miglayoutfx2/pages/Home
    Start using Mig and you will never look back. I have used it in Swing heavily for commercial apps and it has never let me down.
    If you can't bring yourself to use Mig, and you only want to change the anchor like in your simple example, here's a little cheat that seems to work:
    public void start(Stage stage) throws Exception
        GridPane workArea = new GridPane();
        Scene scene = new Scene(workArea, 800, 600);
        stage.setScene(scene);
        stage.show();
        Button button = new Button("Test");
        workArea.add(button, 0, 0);
        workArea.setAlignment(Pos.CENTER_LEFT);
        workArea.setAlignment(Pos.CENTER_RIGHT);
        workArea.setAlignment(Pos.CENTER);
    }This sidesteps the whole add/remove issue.
    Cheers,
    zonski

  • Is there a bug with StackedBarChart when assigned to a BorderPane?

    Hi All,
    I just want to confirm if other programmers are having problems with adding a StackedBarChart to a BorderPane?
    Before submitting a bug through JIRA.
    When adding all other charts (Bar Chart, Line Chart, Scatter Chart) these all work fine with a BorderPane.
    Furthermore I can definitely confirm the StackedBarChart is NOT empty as I have tested for this occasion
    using:
    if(stackedBarChart.getData().isEmpty() == true){Print Message here!}
    else{Print Message here! We have data!}Whenever I try this line:
    newChartLayoutFirst.setCenter(stackedBarChart);I get the following error message:
    java.lang.NullPointerException
         at java.util.ArrayList.addAll(ArrayList.java:530)
         at javafx.scene.chart.StackedBarChart.updateAxisRange(StackedBarChart.java:360)
         at javafx.scene.chart.XYChart.layoutChartChildren(XYChart.java:620)
         at javafx.scene.chart.Chart$1.layoutChildren(Chart.java:84)
         at javafx.scene.Parent.layout(Parent.java:1018)
         at javafx.scene.Scene.layoutDirtyRoots(Scene.java:513)
         at javafx.scene.Scene.doLayoutPass(Scene.java:484)
         at javafx.scene.Scene.access$3900(Scene.java:169)
         at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2199)
         at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
         at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:460)
         at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:329)
         at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
         at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
         at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:67)
         at java.lang.Thread.run(Thread.java:722)I'm using JavaFX 2.2.0 with JDK 7u6 on a Windows 7 x64 machine.
    Edited by: 863626 on Dec 10, 2012 10:20 PM

    Don't worry I've worked it out myself, stupid me missed one small critical piece of information pertaining to StackedBarCharts.
    I forgot to assign the setCategories method to one of my axis. Doh!

  • Populated TableView in a BorderPane

    Hi everyone,
    I have a populated TableView object which I have added to my BorderPane layout. More specifically, this table is added to the center pane of the BorderPane object.
    As-is, this table only occupies 300px * 300px of this center pane. Is there a behavior enabling the table to use up all the space in the center pane?
    Code segment:
    @Override
         public void start(Stage stage) throws Exception {
              // instantiate group and add widget as root node
              Group rootNode = new Group();
                    BorderPane layout_main = new BorderPane(); // base layout for application           
                    TableView<Person>table = new TableView<Person>(); // instantiate a table of 'Person' objects
                    TableColumn<Person>column_name = new TableColumn<Person>("Name"); // only 1 column...'name'
                    column_name.setProperty("name");
                    // instantiate list to store 'person' objects
                    ObservableList<Person>list = FXCollections.observableArrayList();
              // code for populating list...
                    // add list to table as well as column
                    table.setItems(list);
              table.getColumns().addAll(column_name);
                    // set the populated table to the center pane
                    // CONCERN:
                    // ... can this table span the entire center of the layout?
                    // why is it only taking up a small region of the center pane?
              layout_main.setCenter(table);
                    rootNode.getChildren().add(layout_main);
              // declare behaviors of the scene, and make visible
              Scene scene = new Scene(rootNode);
              stage.setScene(scene);
              stage.setWidth(600);
              stage.setHeight(600);
              stage.setTitle("Example Application");
              stage.setVisible(true);
         }I'd be very appreciative for any leads.
    Thank you,
    p.

    Try to use your BorderPane directly as a scene root, eliminating Group at all.
    I mean instead of:
    rootNode.getChildren().add(layout_main);
    Scene scene = new Scene(rootNode);Just use:
    Scene scene = new Scene(layout_main);

  • ScaleTransition on a Node within a BorderPane

    I would like to apply a ScaleTransition on e.g. a Text.
    Beside this Text I have many other nodes and all Nodes are layout in a BorderPane. The ScaleTransition is only applied to Text
    Now when I make a ScaleTransition on this text, then what happens is all other nodes are affected as well. How can I make that the Transtion effects only the Text ?
    It looks like the BorderPane tries to adjust the positioning of all the nodes during the Transition
    Edited: I think it is not an issue of BorderPane..but which Panel am I supposed to use ? I want to grow and shrink the text only without affecting other nodes.
    Edited by: Marcello on 07.03.2012 01:20

    I'm not sure in your specific case, but all of the containers have different properties as to how they calculate their size based on their children. It's pretty clearly documented in the javadocs. For StackPane it attempts to resize each child to fill its content area, and its minimum and preferred sizes are based on the largest child.
    Good that it works though.

  • How can I implement a status bar at the bottom of a resizable application?

    Hello all,
    I am a JavaFx newbie and I am implementing an application (a Sokoban game), with a menu at the top of the frame and a gaming area covering the rest of the frame. To support the game, I have to load images at certain positions in the gaming area.
    The game also includes a level editor with another menubar and where images are set to other positions.
    I implemented this in another view, swiching from the game mode to the level editor mode and vice versa is just done by setting the other view visible. Up to now this works, here the important statements building these details:
    Group root = new Group();
    gameView = new Group(); // for gaming mode
    le_view = new Group()   // for level editor mode
    MenuBar gameMenubar = new MenuBar();
    Menu menuGame = new Menu(bundle.getString("MenuGame"));
    ... building the menu items and menues ...
    gameView.getChildren().add(gameMenubar);
    ImageView buildingView[][] = new ImageView[22][22];
    for (nCol = 0; nCol < 22; nCol++) {
        for (nRow = 0; nRow < 22; nRow++) {
            buildingView[nCol][nRow] = new ImageView();
            buildingView[nCol][nRow].setX(nCol * 26 + 5);
            buildingView[nCol][nRow].setY(nRow * 26 + 40);
            gameView.getChildren().add(buildingView[nCol][nRow]);
    gameView.setVisible(true);
    root.getChildren().add(gameView);
    ... same stuff to build the le_view ...
    le_View.setVisible(false);
    root.getChildren().add(le_View);
    Scene scene = new Scene(root, 800, 600, Color.CORNSILK); Now I want to introduce a status bar at the bottom of the frame, which of course has to follow the bottom of the frame, if it is resized. And of course the menu and the status bar should not grow vertically, if the height of the frame is increased.
    The implementation seems to be easy with StackPane for the frame and one BorderPane for each mode.
    For the first step I only tried implementing the game mode with only one BorderPane (just setting the menu, the gaming area and the status bar each into a HBox and setting these three HBoxes at the top, into the center and at the bottom). I also tried this via GridPane and via VBox; I always get any erroneous behaviour:
    Either the menubar is visible, but the menus do not pop up the menu items, or the anchor point of the menu and of gaming area are set 100 pixels left of the left frame border and move into the frame when the frame width is increased, or the menu is set 20 pixels below the top of the frame, or HBox with the menu grows when the frame height is increased, so that the anchor point of the gaming area moves down.
    Can you describe me a correct construction of such a frame? Thanks in advance.
    Best regards
    Gerhard

    Hello Gerhard,
    Glad the code helped, thanks for a fun layout exercise.
    For the draft code I just pulled an icon off the internet over a http connection.
    If you haven't done so already place any icons and graphics you need local to your project, so that resource lookups like:
    Image img = new Image("http://www.julepstudios.com/images/close-icon.png");become
    Image img = new Image("close-icon.png");then performance may improve.
    Another possible reason for your performance problem could be that when you use a vbox, the vbox content can overflow the area of the borderpane center and might be sitting on top of the menu pane, making you unable to click the menu (which is what happens to me when I try that with the draft program with the vbox wrapping mod, then resize the scene to make it smaller). This was a trick which caught me and the reason that I used a Group originally rather than a vbox. I found a vbox still works but you need to tweak things a bit. The trick I saw was that the order in which you add stuff to the borderpane is important. The borderpane acts like a stack where the last thing added floats over the top of everything else if you size the scene small enough. For your project you want the menu on top always, so it always needs to be the last thing added to the borderpane, but when you swap in the level pane for the game pane, then back out again, the game pane can end up on top of the menu which makes the menu seem like you can't click it (only when the scene is sized small enough). It was quite a subtle bug which took me a little while to work out what was happening. For me the solution was to add just one vbox to the center of the border, and then swap the game pane and the level editor in and out of the vbox, that way the center of the layout always stayed behind the menu bar and the status bar.
    I added some revisions to reflect the comments above and placed some comments in the code to note what was changed and why.
    public class SampleGameLayoutRevised extends Application {
      public static void main(String[] args) { Application.launch(args); }
      public void start(Stage stage) throws Exception {
        final BorderPane gameLayout = new BorderPane();
        final Group gameView = new Group();
        final MenuBar gameMenubar = new MenuBar();
        final Menu gameMenu = new Menu("Mode");
        final VBox centerView = new VBox();
        centerView.setStyle("-fx-background-color: darkgreen");  // we set a background color on the center view to check if it overwrites the game menu.
        MenuItem playGameMenu = new MenuItem("Play Game");
        MenuItem levelEditMenu = new MenuItem("Edit Levels");
        gameMenu.getItems().add(playGameMenu);
        gameMenu.getItems().add(levelEditMenu);
        gameMenubar.getMenus().add(gameMenu);
        final StackPane levelEditView = new StackPane();
        levelEditView.getChildren().add(new Text("Level Editor"));
        ImageView buildingView[][] = new ImageView[22][22];
        Image img = new Image("http://www.julepstudios.com/images/close-icon.png");  // use of http here is just for example, instead use an image resource from your project files.
        for (int nCol = 0; nCol < 22; nCol++) {
          for (int nRow = 0; nRow < 22; nRow++) {
            ImageView imgView = new ImageView(img);
            imgView.setScaleX(0.5);
            imgView.setScaleY(0.5);
            buildingView[nCol][nRow] = imgView;
            buildingView[nCol][nRow].setX(nCol * 20 + 5);
            buildingView[nCol][nRow].setY(nRow * 20 + 40);
            gameView.getChildren().add(buildingView[nCol][nRow]);
        final VBox statusBar = new VBox();
        final Text statusText = new Text("Playing Game");
        statusBar.getChildren().add(statusText);
        statusBar.setStyle("-fx-background-color: cornsilk"); // we set a background color on the status bar,
                                                              // because we can't rely on the scene background color
                                                              // because, if the scene is sized small, the status bar will start to overlay the game view
                                                              // and if we don't explicitly set the statusBar background the center view will start
                                                              // to bleed through the transparent background of the statusBar.
        gameLayout.setCenter(centerView); // we add the centerview first and we never change it, instead we put it's changeable contents in a vbox and change out the vbox content.
        gameLayout.setBottom(statusBar);
        gameLayout.setTop(gameMenubar);   // note the game layout is the last thing added to the borderpane so it will always stay on top if the border pane is resized.
        playGameMenu.setOnAction(new EventHandler<ActionEvent>() {
          public void handle(ActionEvent event) {
            centerView.getChildren().clear();  // here we perform a centerview vbox content swap.
            centerView.getChildren().add(gameView);
            statusText.setText("Playing Game");
        levelEditMenu.setOnAction(new EventHandler<ActionEvent>() {
          public void handle(ActionEvent event) {
            centerView.getChildren().clear();  // here we perform a centerview vbox content swap.
            centerView.getChildren().add(levelEditView);
            statusText.setText("Editing Level");
        playGameMenu.fire();
        Scene scene = new Scene(gameLayout, 800, 600, Color.CORNSILK);
        stage.setScene(scene);
        stage.show();
    }Other than that I am not sure of a reason for the slowdown you are seeing. In my experience JavaFX has been quick and responsive for the tasks I have been using it for. Admittedly, I just use if for a bunch of small trial projects, but I've never seen it unresponsive for a minute.
    - John

  • Label bounds bigger than they really are

    I have a question regarding the calculation of the bounds of labels and how they are used to take up space in a parent.
    In my example, i have an application where the top element is a border pane. In the left part of the borderpane i have a VBox with a specified maxWidth (in this case, 250). The last element of the VBox is another VBox to display a label (a headline) and a GridPane. In this GridPane i have several other labels. Consider this picture:
    pic1
    This is how it should look like (i enabled gridLinesVisible for sake of demonstration).
    When i use a Text instead of a label in the right column, i get this:
    pic2
    Since the Text in the second row exceeds the maxWidth of the top VBox but cannot be made smaller, the VBox grows in width. Everything ok here.
    But when i use a label, i expect the label to respect the maxWidth of the top VBox. Altough it seems that it does this, see the result:
    pic3
    The label cuts the text at the correct place and the grid column is not larger than the needed space, but still the VBox width grew.
    Is this a bug or am i doing something wrong? When i set the ColumnConstraints of the GridPane to a value, i get the result of the first picture. But this workaround isn't practicable since it's a hazzle to find out the right amount of pixels and what i really want is the label to fill the remaining space it has available from the top VBox.

    jsmith wrote:
    Should i write a minimal example for reproducing this issueYes.Main.java:
    package labelboundsissue;
    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.geometry.Pos;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.shape.Line;
    import javafx.stage.Stage;
    import java.net.URL;
    public class Main extends Application {
      public static void main(String[] args) {
        launch(args);
      @Override
      public void start(Stage primaryStage) throws Exception {
        BorderPane pane = new BorderPane();
        StackPane center = new StackPane();
        center.setAlignment(Pos.CENTER_LEFT);
        Label someLabel = new Label("  Label Bounds Issue Test");
        Line line = new Line(0,0,0,500);
        center.getChildren().addAll(line, someLabel);
        pane.setCenter(center);
        FXMLLoader loader = new FXMLLoader();
        URL resource = getClass().getResource("left.fxml");
        loader.setLocation(resource);
        Parent  left = (Parent) loader.load();
        pane.setLeft(left);
        Scene scene = new Scene(pane, 800, 500);
        primaryStage.setScene(scene);
        primaryStage.show();
    }left.fxml:
    <?xml version="1.0" encoding="utf-8"?>
    <?import java.lang.*?>
    <?import java.net.URL?>
    <?import javafx.scene.shape.*?>
    <?import javafx.scene.control.*?>
    <?import javafx.scene.paint.*?>
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.image.*?>
    <?import javafx.geometry.Insets?>
    <?import javafx.scene.text.*?>
    <?import javafx.scene.web.*?>
    <?import javafx.scene.*?>
    <VBox maxWidth="200">
      <GridPane gridLinesVisible="true" hgap="5">
        <columnConstraints>
          <ColumnConstraints hgrow="NEVER"/>
          <ColumnConstraints hgrow="NEVER"/> <!-- comment this -->
          <!--<ColumnConstraints hgrow="NEVER" maxWidth="155"/>--> <!-- uncomment this -->
        </columnConstraints>
        <Text GridPane.columnIndex="0" GridPane.rowIndex="0" text="Name:"/>
        <Label GridPane.columnIndex="1" GridPane.rowIndex="0" text="Karl Theodor Maria Nikolaus Johann Jacob Philipp Franz Joseph Sylvester Freiherr von und zu Guttenberg" />
      </GridPane>
    </VBox>When starting the application you can see vast amount of space between the end of the label and the left border of the border pane, altough it should be limited by the VBox' maxWidth.
    Adjusting the maxWidth of the Column solves it.

  • Get the duration of all mp3 files inside a directory

    Hello everyone,
    I am working on a little project done with swing. Since I need an mp3 player inside my swing application, I found a really good solution with JavaFX 2. I have never worked with JavaFX before, therefor it seems to me a little bit strange on some parts.
    Anyway.
    I created a button on my application and as soon as somebody presses that button, the application should scan recursivly a unique directory for mp3 files and store the information of artist, title and track length into a database.
    The mp3 player I created is based on the example from this page:
    http://www.java2s.com/Code/Java/JavaFX/Mp3playerwithmetadataviewandcontrolpanel.htm
    I understand the source code for most parts, but some behaivors are not really clear to me. My thoughts about getting the complete length of the mp3 file was
    media.getDuration
    or
    mediaplayer.getTotalDuration
    but both results are NaN if I call .toMillis();
    Instead I need to create a listener (why?)
    private class TotalDurationListener implements InvalidationListener {
        @Override
        public void invalidated(Observable observable) {
          final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
          final Duration totalDuration = mediaPlayer.getTotalDuration();
          totalDurationLabel.setText(formatDuration(totalDuration));
      }and register this listener on the mediaplayer
    mp.totalDurationProperty().addListener(new TotalDurationListener());I can image that the mediaplayer can "host" several media objects somewho and the listener is called as soon as a new media will be added to the mediaplayer in order
    the calculate the overall duration.
    When is this listener exactly called and is there no other ways to get the total length of the mp3 file?
    Here is a minimal example which should work without any external libs
    package de.hauke.schwimmbad.application.playground;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import javafx.application.Platform;
    import javafx.beans.property.ReadOnlyObjectWrapper;
    import javafx.embed.swing.JFXPanel;
    import javafx.scene.Scene;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.paint.Color;
    import javafx.util.Duration;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.UIManager;
    public class Testing10 extends JFrame {
         private MediaPlayer mediaPlayer;
         private final ReadOnlyObjectWrapper<MediaPlayer> mediaPlayerWrapper = new ReadOnlyObjectWrapper<MediaPlayer>(
                   this, "mediaPlayer");
         public static void main(String[] args) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                   new Testing10();
              } catch (Exception ex) {
                   System.out.println(ex);
         public Testing10() {
              super();
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLayout(null);
              setSize(500, 500);
              setTitle("Testing");
              setLocationRelativeTo(null);
              setResizable(false);
              JButton button = new JButton("Scan");
              button.setBounds(10, 10, 150, 30);
              add(button);
              button.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent arg0) {
                        scan();
              final JFXPanel fxPanel = new JFXPanel();
              fxPanel.setBounds(30, 80, 300, 300);
              add(fxPanel);
              Platform.runLater(new Runnable() {
                   public void run() {
                        initFX(fxPanel);
              setVisible(true);
         private void scan() {
              File directory = new File("C:\\dev\\mp3");
              List<File> mp3Files = new ArrayList<File>();
              for (File file : directory.listFiles()) {
                   if(file.getName().endsWith("mp3")) {
                        mp3Files.add(file);
              for (File file : mp3Files) {
                   System.out.println(file.getAbsoluteFile());
                   getLength(file);
         private Duration getLength(File file) {
              if(mediaPlayer != null) {
                   mediaPlayer.stop();
              final Media media = new Media(file.toURI().toString());
              mediaPlayer = new MediaPlayer(media);
              mediaPlayerWrapper.setValue(mediaPlayer);
              if(media.durationProperty()==null) System.out.println("durationProperty ist null");
              if(media.durationProperty().get()==null) System.out.println(".get() ist null");
              System.out.println("---> " + media.durationProperty().get().toMillis());
              return media.getDuration();
         private void initFX(JFXPanel fxPanel) {
              BorderPane root = new BorderPane();
              Scene scene = new Scene(root, Color.ALICEBLUE);
              fxPanel.setScene(scene);
    }The other question is why do I need a listener for the meta data to be changed in order to get the meta data?
    media.getMetadata().addListener(new MapChangeListener<String, Object>()Why can't I call something like
    media.getMetadata() --> returns a filled map?
    The metadata problem is not included inside the example from above.
    Sorry for my english but I hope everybody can understand the issue.
    Many greetings,
    Hauke

    The nature of the Media class is that it accesses it asynchronously. This means that when you create an instance of it, and then immediately query it, the data you want may not be available yet. This is all in the Javadoc, see the doc for Media:
    The media information is obtained asynchronously and so not necessarily available immediately after instantiation of the class. All information should however be available if the instance has been associated with a MediaPlayer and that player has transitioned to MediaPlayer.Status.READY statusSo you could associate the Media with a MediaPlayer, and then wait until it goes to the Status READY, and then read the length of the Media.
    As for your 2nd question, getMetadata() returns a Map. You can just loop through it:
      for(Map.Entry<String, Object> entry : media.getMetadata()) {
        // etc
      }However, the same restrictions apply as with Media -- you will probably need to wait before the information is available -- that's why the Listener approach works, because it will notify you as soon as the information is added to the map.

  • How can I display a new scene in JavaFX 2.2? For example after button click

    how to display new scene after button click in the main window, I want the main window and the new scene are in one stage. thx

    You can change the scene by calling stage.setScene(new Scene(newContentParent));
    I don't think you are quite asking for a complete scene change though as you "want the main window and the scene in one stage". The main window is a stage (as Stage extends Window). And a given stage can only contain one scene at a time (though you can swap it out by calling setScene as described earlier).
    What I think you are really asking for how can you replace some content part of the active Scene on the Stage. To do that you can set a layout manager like a HBox or a BorderPane as the root of your scene, then change out the content of the layout manager. For example:
    final BorderPane layout = new BorderPane();
    layout.setCenter(new Label("Dogbert");
    final Button nav = new Button("Next");
    layout.setLeft(nav);
    nav.setOnAction(new EventHandler<ActionEvent>() {
      @Override public void handle(ActionEvent actionEvent) {
        layout.setCenter(new Label("Dilbert"));       
    });In the above short sample code, if you wanted to change the scene rather than the a pane, then you would call stage.setScene rather than layout.setCenter.
    There is a complete executable example with multiple content panes and some styling here:
    http://stackoverflow.com/questions/13556637/how-to-have-menus-in-java-desktop-application

  • How do I create an infinite drawing canvas in a ScrollPane?

    I wanted to figure this out on my own, but it is time to ask for help. I've tried too many different things. The closest I've come to the behaviour I want is with this code:
    final BorderPane root = new BorderPane();
    final Pane canvasWrapper = new Pane();
    canvasWrapper.setPrefSize(800, 500);
    canvasWrapper.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    canvasWrapper.setStyle("-fx-background-color: lightgray; -fx-border-color: green; -fx-border-width: 2px;");
    final Group canvas = new Group();
    canvasWrapper.getChildren().add(canvas);
    final ScrollPane scroll = new ScrollPane();
    scroll.setContent(canvasWrapper);
    root.setCenter(scroll);
    // event code for adding circles and lines to the canvas
    I want the ScrollPane to be filled with the Pane, so it can catch events for drawing. When the stage is resized, the ScrollPane is resized too. This the result of the BorderPane. What I want is to expand the window and have canvasWrapper expand to fill the entire ScrollPane viewport. When the stage is made smaller the ScrollPane shrinks, but I want the canvasWrapper to retain its size. The idea is the drawing canvas can only grow. When it gets too large for the current stage/ScrollPane size, the scrollpane can be used to navigate around the canvas.
    I tried using
    scroll.setFitToHeight(true);
    scroll.setFitToWidth(true);
    but this causes the Pane to be made smaller when the viewport is made smaller.

    I figured it out!
    Use
    scroll.setFitToHeight(true);
    scroll.setFitToWidth(true);
    to resize the Pane as the view port changes.
    Save the canvas' size as the Pane's size.
    canvas.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
                @Override
                public void changed(ObservableValue<? extends Bounds> ov, Bounds t, Bounds t1) {
                    canvasWrapper.setMinSize(t1.getMaxX(), t1.getMaxY());
    This forces the Pane to always be as large as the group is.
    Missed a piece of code - jrguenther

Maybe you are looking for