Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX 8 Localization of dialog's internal elements

I am currently developing a JavaFX application with Slovak language localization and inside the application I am using an Alert dialog for showing exceptions with expandable content pane as shown below on images:

show details - alert screenhide details - alert screen

I would like to have this dialog completely translated which is going well with Header, Title or Content but I cannot find a way how to translate the Show/Hide details label of the expandable area.

So my question can be a little bit generalized: How to change/translate text of JavaFX internal elements?

Thanks in advance for any help.

PS: For creation of this Alert dialog for exceptions I am using code as found on code.makery.ch

like image 738
Martin Vrábel Avatar asked May 13 '15 11:05

Martin Vrábel


1 Answers

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
like image 151
Uluk Biy Avatar answered Oct 02 '22 01:10

Uluk Biy