JavaFX title bar RTL not supported?

别说谁变了你拦得住时间么 提交于 2019-12-04 19:27:01

You need to invoke setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT) on the scene before showing the stage primaryStage.show():

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        Scene scene = new Scene(root, 300, 275);
        primaryStage.setScene(scene);
        scene.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
        primaryStage.show();
    }


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

Because the orientation of children might be different for each child, the orientation of a child node when explicitly set can override the parent. For example, the top level window might be right-to-left, with the title and close box appearing on the left.

Reza

Just like what @Eng.Fouad said for scene object can be done for menubar. Invoking

setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT)

for the menubar object makes it rtl:

MenuBar menuBar = new MenuBar();
menuBar.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);

except that the arg for this method can be

NodeOrientation.LEFT_TORIGHT

which makes it left to right and

NodeOrientation.INHERIT

that gets its value from the parent container.

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