7

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 screen hide 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

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Martin Vrábel
  • 830
  • 1
  • 13
  • 36
  • looks like a bug to me - if the Locales are available, all localizable strings should be translated. You might consider filing a report in fx issue tracker (if it's still online, heard it will be merged with core jdk tracker sometime this month) – kleopatra May 13 '15 at 11:48
  • @kleopatra I am not using correct localization with setting Locales or something. I just set all labels that have available public setters. Should I use correct localization to solve it? – Martin Vrábel May 13 '15 at 11:59
  • hmm .. Slovak isn't provided by core jdk? Or just not by fx? – kleopatra May 13 '15 at 12:16
  • @kleopatra No, Slovak language is not betwwen default Locales. – Martin Vrábel May 13 '15 at 12:18
  • oops, that's bad :-( Faintly remember that there's a way to hook a custom locale provider into the system, but don't remember any details, sorry. – kleopatra May 13 '15 at 12:43

1 Answers1

3

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
Community
  • 1
  • 1
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • This looks really good but I've got problem to lookup the ```.details-button``` hyperlink. In debugger I can see that ```dialogPane``` has property ```detailsButton``` but the lookup method returns ```null``` and I don't know how to get it from there. I've tried several variations of string but with no success. – Martin Vrábel May 13 '15 at 16:39
  • @Supermartzin Works for me. You probably didn't put your code inside Platform.runLater(). – Nikša Baldun May 13 '15 at 17:45
  • @NikšaBaldun Thanks! I forgot that part and I also found out that I have been using another property. Now everything works well! – Martin Vrábel May 13 '15 at 18:17