2015-09-08 5 views
1

У меня возникает проблема в моем коде, потому что он переводит несколько слов (в данном случае кнопку) в соответствии с языком os. Я искал решения, но я не нашел ничего, чтобы соответствовать моему делу. Насколько я видел, связки используются для перевода строк.диалог интернационализации в javafx

Вот моя проблема явно: enter image description here

Моя проблема заключается в том, что вместо того, чтобы отменить это пишет «Annuler», французское слово.

Вот код диалога:

printerSet.setOnAction(new EventHandler<ActionEvent>() { 
     @Override 
     public void handle(ActionEvent e) { 
      ChoiceDialog<String> dialog = new ChoiceDialog<>(
        "Dummy Printer", choices); 
      dialog.setTitle("Choice Dialog"); 
      dialog.setHeaderText(null); 
      dialog.setContentText("Choose the printer you want to use:"); 

      Optional<String> result = dialog.showAndWait(); 
      if (result.isPresent()) { 
       String opt = result.get(); 
       System.out.println("Your choice: " + opt); 
       printerLabel.setText("Selected Printer: " + opt); 
      } 

      printButton.setDisable(true); 
      name.setText(""); 
      code.setText(""); 
      description.setText(""); 
      availability.setText(""); 
     } 
    }); 

Кто-нибудь знает решение?

ответ

1

Try предоставить следующие аргументы JVM при запуске:

java -Duser.language=en -Duser.country=US ... 
0

Вы можете добавить кнопки вручную:

MVCE:

import java.util.Optional; 

import javafx.application.Application; 

import javafx.scene.control.ButtonBar.ButtonData; 
import javafx.scene.control.ButtonType; 
import javafx.scene.control.ChoiceDialog; 
import javafx.scene.control.Label; 
import javafx.stage.Stage; 

public class MCVE extends Application { 

    @Override 
    public void start(Stage stage) { 

     ChoiceDialog<String> dialog = new ChoiceDialog<>(
       "Dummy Printer"); 
     dialog.setTitle("Choice Dialog"); 
     dialog.setHeaderText(null); 
     dialog.setContentText("Choose the printer you want to use:"); 

     // Remove the default buttons and then add your custom ones. 
     dialog.getDialogPane().getButtonTypes().clear(); 
     dialog.getDialogPane().getButtonTypes().add(
       new ButtonType("OK", ButtonData.OK_DONE)); 
     dialog.getDialogPane().getButtonTypes().add(
       new ButtonType("Cancel", ButtonData.CANCEL_CLOSE)); 

     Optional<String> result = dialog.showAndWait(); 
     if (result.isPresent()) { 
      String opt = result.get(); 
      System.out.println("Your choice: " + opt); 
     } 
    } 

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

Это также может быть достигнуто во время выполнения используя Locale.setDefault(locale) в методе main класса Application.

Например:

public class App extends Application { 

    public static void main(String[] args) { 
     Locale.setDefault(Locale.ENGLISH); 

     try { 
      launch(args); 
     } catch (Throwable e) { 
      // Handle error 
     } 
    } 

} 

Вызов Locale.setDefault(locale) снова после того, как Application.launch() было названо, не оказывает никакого влияния на диалоговых текстов кнопки.

0

Для задачи в вопросе и и вопросе с Умляутами в мастере controlsfx

см https://bitbucket.org/controlsfx/controlsfx/issues/769/encoding-problem-all-german-umlauts-are

Я использую следующий метод: после изменения локало я называю refreshI18n() на моем wizardpanes Для этого я использую производную WizardPane. refreshI18n() вызывается fixButtons(), и там текст кнопки устанавливается в соответствии с установленным языком.

Основная проблема заключается в том, чтобы найти элементы управления и сбросить текст, например. для кнопок

/** 
* https://bitbucket.org/controlsfx/controlsfx/issues/769/encoding-problem-all-german-umlauts-are 
* 
* @param wizardPane 
*/ 
protected void fixButtons() { 
    ButtonType buttonTypes[] = { ButtonType.NEXT, ButtonType.PREVIOUS, 
    ButtonType.CANCEL, ButtonType.FINISH }; 
    for (ButtonType buttonType : buttonTypes) { 
    Button button = findButton(buttonType); 
    if (button != null) { 
     button.setText(buttonType.getText()); 
    } 
    } 
} 

/** 
* get the Button for the given buttonType 
* @return the button 
*/ 
public Button findButton(ButtonType buttonType) { 
    for (Node node : getChildren()) { 
    if (node instanceof ButtonBar) { 
     ButtonBar buttonBar = (ButtonBar) node; 
     ObservableList<Node> buttons = buttonBar.getButtons(); 
     for (Node buttonNode : buttons) { 
     Button button = (Button) buttonNode; 
     @SuppressWarnings("unchecked") 
     ObjectProperty<ButtonData> prop = (ObjectProperty<ButtonData>) button 
      .getProperties().get("javafx.scene.control.ButtonBar.ButtonData"); 
     ButtonData buttonData = prop.getValue(); 
     if (buttonData.equals(buttonType.getButtonData())) { 
      return button; 
     } 
     } 
    } 
    } 
    return null; 
} 
Смежные вопросы