2016-08-18 51 views

回答

2

你应该能够改变nodeOrientationDialogdialogPane

Alert alert = ... 

alert.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); 
0

的Fabian作为曾建议below,你可以这样做简单地

alert.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);


但是,如果有人进来寻找这样的一些手动方式(虽然我不明白为什么有人想要做到这一点),那么请找到下面的细节 -

我不知道语言从右到左工作。但是,TextFlow可以提供从右向左对齐文本的选项。所以这可能会奏效,但我不确定!

此外,以下代码片段不会编辑警报框本身中的文本。但它只是增加了额外的TextFlow到对话框中。

Alert alert = new Alert(AlertType.CONFIRMATION); 
alert.setTitle("Some title"); 

Text text = new Text("some right-to-left text here"); 

TextFlow textFlow = new TextFlow(); 
textFlow.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); 

textFlow.getChildren().addAll(text); 

alert.getDialogPane().setContent(textFlow); 
alert.show(); 

这是我在波斯语中添加了一些Google翻译的'Hello World'后对话框的外观。只是做到了这一点,所以人们会直接知道它是否有效,而不必尝试。

image with persion 'hello world'

头文字似乎在方式获得。所以,你可以通过using-

alert.setHeaderText(null); 

编辑删除:

由于按键都还是英文的(或左右),这里是你可以使用,考虑到你已经做了完整的应用程序右键 - 左键,按照相同的步骤制作右键文本。我不会投入时间,因为这是你已经拥有的东西。

ButtonType okBtn; //make sure this is of type ButtonBar.ButtonData.OK_DONE 
ButtonType cancelBtn; //make sure this is of type ButtonBar.ButtonData.CANCEL_CLOSE 
Alert alert = new Alert(AlertType.CONFIRMATION,"",okBtn,cancelBtn); 
alert.getDialogPane().setContent(textFlow); 

alert.setTitle("Some title"); 
alert.setHeaderText(null); 
Optional<ButtonType> result = alert.showAndWait(); 

如果OK按钮被处理result点击您可以执行的任务 - 检查result.isPresent()是真实的,并检查是否result.get() == okBtn

这段代码的结果(忽略按钮文本) -

enter image description here

如果这个工作,那么请让我知道。如果它不让我知道'它看起来不怎么样'。

0

用途:用于

alert.getDialogPane().getScene().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); 

代替:

alert.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); 

,使标题栏方向RTL。