JavaFX Fill empty space when component is not displayed?

I am using Linux Suse 12.3, JDK 1.7.0-45, JavaFX 2.2.

my Question: why the following code does not work and how to implement the toggleShow / hide function?

here is my test code:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

public class Test extends Application {
    public static void main(String[] args) { 
        launch(args); 
    }

    @Override
    public void start(final Stage stage) {
        AnchorPane root = new AnchorPane();


        BorderPane inner = new BorderPane();

        AnchorPane.setTopAnchor(inner, 0.0);
        AnchorPane.setRightAnchor(inner, 0.0);
        AnchorPane.setBottomAnchor(inner, 0.0);
        AnchorPane.setLeftAnchor(inner, 0.0);

        final HTMLEditor center = new HTMLEditor();

        final ToolBar top = new ToolBar();
        final Button button = new Button("hide");
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent t) {
                top.setVisible(false);
                //center.setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
            }
        });     

        center.setManaged(false);
        top.getItems().add(button);
        //top.managedProperty().bind(top.visibleProperty());
        top.setManaged(false);

        inner.setTop(top);
        inner.setCenter(center);

        root.getChildren().add(inner);
        Scene scene = new Scene(root,600,400);
        stage.setScene(scene);
        stage.show();
    }
}

what I want is the same effect as Sergey’s decision on this question, but without changing the width / height !:

How to solve the coincidence of controls with each other belonging to two different panels

as I said, this is just test code. I tried using other layouts like BorderPane but still didn't work. I do not want to recalculate the size manually ... etc. Removing the node and adding it again is not an option for me.

What happened in my code? any idea is welcome! thanks

+4
2

BorderPane , - javadoc:

BorderPane ; .

, AnchorPane :

AnchorPane.setTopAnchor(inner, 0.0);
AnchorPane.setRightAnchor(inner, 0.0);
AnchorPane.setBottomAnchor(inner, 0.0);
AnchorPane.setLeftAnchor(inner, 0.0);

. VBox .

:

@Override
public void start(final Stage stage) {
    final HTMLEditor center = new HTMLEditor();
    final ToolBar top = new ToolBar();

    final Button button = new Button("hide");
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            top.setVisible(false);
            top.setManaged(false);
        }
    });
    top.getItems().add(button);

    VBox inner = new VBox();
    inner.getChildren().addAll(top, center);
    Scene scene = new Scene(inner, 600, 400);
    stage.setScene(scene);
    stage.show();
}

:
"" "/"? .

+5

top.setManaged(false);, Group :

    Group g = new Group();
    Region spacer = new Region();
    spacer.setPrefWidth(10000);
    spacer.setMinWidth(100);    
    top.getItems().add(spacer);
    g.getChildren().add(top); //Toolbar here...
    inner.setTop(g); //set Group into Borderpane instead of the toolbar

HTML-.

0

All Articles