JavaFx:我如何用屏幕分辨率绑定一个舞台? [英] JavaFx: How i can bind a stage with screen resolution?

查看:143
本文介绍了JavaFx:我如何用屏幕分辨率绑定一个舞台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究javaFx项目,我在笔记本电脑上创建,一切都很好,但是当我改变我的屏幕,现在我使用大屏幕,我发现我的应用程序受到屏幕分辨率的影响,某些组件不适合屏幕。
这是我的代码:

I'm working on javaFx project,i created on my laptop ,every thing is well ,but when i changed my screen , now i use large screen , i found that my application affected with screen resolution some components do not fit on the screen. This is my code :

 try {

                        FXMLLoader fxm = new FXMLLoader(getClass().getResource("Home.fxml"));

                        //Load th file XML To parent
                        Parent parent = (Parent) fxm.load();
                        //Create a new stage         

                        s.setTitle("PubWorks 1.0");
                        s.getIcons().add(new Image("/Images/Casque.png"));

                        Scene scene = new Scene(parent);
                        s.setScene(scene);
                        s.centerOnScreen();
                        ((Node) event.getSource()).getScene().getWindow().hide();
                        s.show();
                        s.setOnCloseRequest(new EventHandler<WindowEvent>() {
                            @Override
                            public void handle(WindowEvent event) {
                                new RecentMessageDao().Delete(new RecentMessage(0));
                                User user = new User(UserTxt.getText(), PasswordTxt.getText());
                                new UserDao().setOff(user);
                                System.exit(0);

                            }
                        });
                        MenuController controller = fxm.getController();
                        controller.getMenuController(s);

                    } catch (Exception exception) {
                        exception.printStackTrace();

                    }

这是我的父布局

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="710.0" prefWidth="1360.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hmproject.MenuController"> ........</AnchorPane>


推荐答案

这是你可以遵循的模式

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <VBox layoutX="168.0" layoutY="30.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <AnchorPane prefHeight="52.0" prefWidth="600.0" style="-fx-background-color: pink;" />
            <HBox prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
               <children>
                  <AnchorPane prefHeight="309.0" prefWidth="113.0" style="-fx-background-color: lightgreen;" />
                  <AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: lightblue;" HBox.hgrow="ALWAYS" />
               </children>
            </HBox>
            <AnchorPane prefHeight="39.0" prefWidth="600.0" style="-fx-background-color: yellow;" />
         </children>
      </VBox>
   </children>
</AnchorPane>


这篇关于JavaFx:我如何用屏幕分辨率绑定一个舞台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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