最小化面板按钮

时间:2014-01-24 23:16:59

标签: javafx javafx-2 javafx-8

我正在研究这个简单面板的例子。

enter image description here

public class MainApp extends Application {

    private static BorderPane bp;

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


        FlowPane flow = new FlowPane();
        flow.setPadding(new Insets(50, 5, 5, 5));
        flow.setVgap(15);
        flow.setHgap(15);
        flow.setAlignment(Pos.CENTER);

        HBox thb = new HBox();
        thb.setPadding(new Insets(13, 13, 13, 13));
        thb.setStyle("-fx-background-color: gray");

        DropShadow ds = new DropShadow();
        ds.setOffsetY(3.0);
        ds.setOffsetX(3.0);
        ds.setColor(Color.GRAY);

        bp = new BorderPane();
        bp.setEffect(ds);
        bp.setPrefSize(600, 500);
        bp.setMaxSize(600, 500);

        bp.setStyle("-fx-background-color:  white;");
        bp.setTop(thb);
        flow.getChildren().add(bp);
        Scene scene = new Scene(flow, 1200, 800);
        scene.getStylesheets().add("/styles/Styles.css");

        stage.setScene(scene);
        stage.show();
    }


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

}

你能帮我创建一个最小化面板的按钮。我想点击按钮缩小面板的大小。

1 个答案:

答案 0 :(得分:1)

我基本上不明白你想做什么。我想这可能会对你有帮助。

    final Button btnmin = new Button();
    flow.getChildren().add(btnmini)
    btnmin.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("mini.gif"))));

    btnmin.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
          Stage stage = (Stage)btnmin.getScene().getWindow();
          stage.setIconified(true);
        }
    });