如何通过java中的按钮最小化,最大化和恢复? [英] How to minimize, maximize and restore down through buttons in java?

查看:1095
本文介绍了如何通过java中的按钮最小化,最大化和恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个JavaFX 2.2程序,并且需要创建自定义UI控件(只是那些始终存在的最小化 - 最大化/恢复 - 关闭按钮在顶部)。我需要为此目的创建自定义按钮,直到创建简单。

I'm creating a JavaFX 2.2 program, and need to create custom UI controls (just those ever-present minimize-maximize/restore-close buttons on the top). I need to create custom buttons for that purpose, simple till just creating.

我只需要最小化的真实代码和最大化/恢复按钮(关闭按钮相当于孩子的游戏)。最小化按钮可将应用程序恢复到任务栏。最大化按钮,最大化它以适应用户的屏幕,并在最大化时切换以恢复按钮。单击恢复的按钮后,窗口将恢复为其初始大小(1200x600)。

I just need the real code for minimize and the maximize/restore buttons (close button was fairly a child's play). The minimize button restores the app to the taskbar. The maximize button, well, maximizes it to fit the user's screen and it toggles to restore button while maximized. When the restored button is clicked, the window gets restored to its initial size (1200x600).

我试过 stage.setSize(width,height) ; 在我的fxml文件中用于还原,但它不起作用( stage 高位作为错误,而舞台名称是stage。 )

我用过

I tried stage.setSize(width, height); in my fxml file for restore down, but it doesn't work (stage is highlited as the error, while the stage name is stage.)
I used

    scene.setFill(Color.TRANSPARENT);
    stage.initStyle(StageStyle.TRANSPARENT);

将默认窗口设置为透明。

to set the default window as transparent.

程序(主文件,而不是控制器)是:

The program(main file, not the controller) is:

    Parent root = FXMLLoader.load(getClass().getResource("fxmlfile.fxml"));       

    Scene scene = new Scene(root);
    scene.setFill(Color.TRANSPARENT);
    stage.initStyle(StageStyle.TRANSPARENT);

    stage.setTitle("Nothing here");
    stage.setScene(scene);
    stage.show();    

关闭操作的控制器文件是:

The controller file with close action is:

@FXML
private void exitProgramAction(ActionEvent exitProgramEvent) {        
    System.out.println("Killing program...");
    System.exit(0);
}


推荐答案

将阶段最小化为任务bar为您的最小化按钮设置一个类似于此的操作:

To minimize the stage into task bar set an action for your minimize button similar to this:

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

        public void handle(ActionEvent event) {
            Stage stage = (Stage)((Button)event.getSource()).getScene().getWindow();
            // is stage minimizable into task bar. (true | false)
            stage.setIconified(true);
        }
    });

我使用JavaFX 8因此我不知道它是否适用于JavaFX 2.2

I use JavaFX 8 therefore I don't know if it will work with JavaFX 2.2

这篇关于如何通过java中的按钮最小化,最大化和恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆