2014-09-04 128 views
0

我有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

只是做

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

或类似与VBox