Minimize panel button

笑着哭i 提交于 2019-12-12 01:10:09

问题


I'm working on this example of simple panel.

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);
    }

}

Can you help me to create button which minimizes the panel. I want when I click the button to shrink the size of the panel.


回答1:


I don't understand basically what you trying to do. I think this might help you.

    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);
        }
    });


来源:https://stackoverflow.com/questions/21344244/minimize-panel-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!