JavaFX title bar RTL not supported?

大城市里の小女人 提交于 2019-12-06 13:37:24

问题


I cant seem to find a way of making the title bar of my window be RTL. I can make the inner nodes RTL by changing the node orientation property, but not the title bar. So I get a really weird looking app where everything is RTL except the title bar.

How can I fix this?


回答1:


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

  • See Node Orientation in JavaFX:

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.




回答2:


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.



来源:https://stackoverflow.com/questions/26455163/javafx-title-bar-rtl-not-supported

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