问题描述
我目前正在开发一个带有斯洛伐克语语言本地化的JavaFX应用程序,在我正在使用 Alert
对话框中显示可扩展内容窗格的异常,如下图所示:
我想要将此对话框完全翻译,与标题
,标题
或内容
但是我找不到如何翻译可扩展区域的显示/隐藏详细信息
标签的方法。
提前感谢您的帮助。
PS:为了创建异常的警报对话框,我使用的代码可以在
在您的特定用例中,您可以向 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);
});
对于更常见的黑客,请参阅。从那里你需要将以下键放到你的自定义属性文件中:
//翻译这些
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对话框内部元素的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!