2016-08-18 33 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。