2014-12-07 100 views

回答

1

只是做

titledPane.setExpanded(false); 

完整的示例:

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.control.TitledPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

public class TitledPaneExample extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     Label label = new Label("Some content"); 
     Button button = new Button("OK"); 
     VBox content = new VBox(10, label, button); 
     TitledPane titledPane = new TitledPane("Titled Pane", content); 
     button.setOnAction(e -> titledPane.setExpanded(false)); 
     VBox root = new VBox(titledPane); 
     Scene scene = new Scene(root, 250, 400); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

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

它不会关闭titledPane它只是修复它,因为它是 - 密切!或打开 – Yael 2014-12-07 18:47:09

+0

查看更新回答的示例 – 2014-12-07 18:59:29

+0

谢谢!!!!!!!!! – Yael 2014-12-07 21:13:10