JavaFX 8对话框内部元素的本地化 [英] JavaFX 8 Localization of dialog's internal elements

查看:349
本文介绍了JavaFX 8对话框内部元素的本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个带有斯洛伐克语语言本地化的JavaFX应用程序,在我正在使用 Alert 对话框中显示可扩展内容窗格的异常,如下图所示:






我想要将此对话框完全翻译,与标题标题内容但是我找不到如何翻译可扩展区域的显示/隐藏详细信息标签的方法。



<那么我的问题可以稍微概括一下:如何更改/翻译JavaFX内部元素的文本?



提前感谢您的帮助。



PS:为了创建异常的警报对话框,我使用的代码可以在 code.makery.ch

解决方案

在您的特定用例中,您可以向 expandedProperty 添加另一个侦听器,该侦听器将覆盖详细信息按钮中显示的文本:

  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:我的更多文字);
});

//触发侦听器
alert.getDialogPane()。setExpanded(true);
alert.getDialogPane()。setExpanded(false);
});

对于更常见的黑客,请参阅本地化JavaFx控件。从那里你需要将以下键放到你的自定义属性文件中:

  //翻译这些
Dialog.detail .button.more =显示详细信息
Dialog.detail.button.less =隐藏详细信息


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:

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

解决方案

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

这篇关于JavaFX 8对话框内部元素的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆