JavaFX 8 Localization of dialog's internal elements

前端 未结 1 1082
孤街浪徒
孤街浪徒 2021-01-05 10:09

I am currently developing a JavaFX application with Slovak language localization and inside the application I am using an Alert dialog for showing exceptions wi

相关标签:
1条回答
  • 2021-01-05 10:30

    For your particular use case, you can add another listener to expandedProperty which will override the texts shown of "details button":

    Platform.runLater(() ->
    {
        Hyperlink detailsButton = ( Hyperlink ) alert.getDialogPane().lookup( ".details-button" );
    
        alert.getDialogPane().expandedProperty().addListener(
                ( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue ) ->
        {
            detailsButton.setText( newValue ? "My less text" : "My more text" );
        });
    
        // trigger listeners
        alert.getDialogPane().setExpanded( true );
        alert.getDialogPane().setExpanded( false );
    });
    

    For more common hack see Localizing JavaFx Controls. From there you need to put the following keys to your custom properties file:

    // translate these
    Dialog.detail.button.more = Show Details
    Dialog.detail.button.less = Hide Details
    
    0 讨论(0)
提交回复
热议问题