添加布局窗格

时间:2014-09-04 14:23:22

标签: javafx javafx-8 controlsfx

我在ControlsFX 8.0.6和JavaFX 8中有一个非常简单的例子。

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.geometry.Pos;
import javafx.geometry.Side;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.controlsfx.control.HiddenSidesPane;

public class MainApp extends Application
{

    public Node getPanel(Stage stage)
    {

        StackPane stackPane = new StackPane();
        stackPane.setStyle("-fx-padding: 30");

        HiddenSidesPane pane = new HiddenSidesPane();

        Label content = new Label("Content Node");
        content.setStyle("-fx-background-color: white; -fx-border-color: black;");
        content.setAlignment(Pos.CENTER);
        content.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

        pane.setContent(content);

        SideNode bottom = new SideNode("Bottom", Side.BOTTOM, pane);
        bottom.setStyle("-fx-background-color: rgba(255,255,0,.25);");
        pane.setBottom(bottom);

        stackPane.getChildren().add(pane);

        return stackPane;
    }

    class SideNode extends Label
    {

        public SideNode(final String text, final Side side,
            final HiddenSidesPane pane)
        {

            super(text + " (Click to pin / unpin)");

            setAlignment(Pos.CENTER);
            setPrefSize(200, 200);
        }
    }

    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception
    {

        Scene scene = new Scene((Parent) getPanel(stage));

        stage.setTitle("JavaFX and Maven");
        stage.setScene(scene);
        stage.show();
    }

}

我很感兴趣我不仅可以在SideNode上显示文字。我想显示不同的布局控件,如BorderPane和VBox。这可能吗?

1 个答案:

答案 0 :(得分:1)

只做

BorderPane bottomPane = new BorderPane();
// fill bottomPane with stuff...
pane.setBottom(bottomPane);

或类似于VBox