Mac OS X中是否存在使用JFileChooser.showDialog(Component,String)设置标题的错误? [英] Is there a bug setting title using JFileChooser.showDialog(Component, String) in Mac OS X?

查看:119
本文介绍了Mac OS X中是否存在使用JFileChooser.showDialog(Component,String)设置标题的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索没有解决这个问题。

Search doesn't turn anything up for this problem.

我使用简单的代码显示带有自定义标题和接受按钮的JFileChooser对话框:

I'm using simple code to display a JFileChooser dialog with customized title and accept button:

JFileChooser fc = new JFileChooser();
fc.showDialog(null,"MyText");

在Windows 7上按预期工作:显示保存对话框,保存替换为 MyText在Accept按钮上对话框标题。

On Windows 7 this works as expected: a Save Dialog is displayed, with "Save" replaced by "MyText" on the Accept button and dialog title.

但是,在Mac OS X上,只更改了Accept按钮文本 - 对话框标题是空白的。我正在使用Java SE 7和MacOS 10.8.5。

However, on Mac OS X, only the Accept button text is changed - the dialog title is blank. I'm using Java SE 7 and MacOS 10.8.5.

在上面两者之间插入这一行:

By inserting this line between the two above:

fc.setDialogTitle("MyText");

显示正确的标题。这是一个已知问题,和/或其他人是否可以重现此行为?

The correct title is displayed. Is this a known issue, and/or can anyone else reproduce this behavior?

推荐答案

您在Windows上遇到的不是期望行为(因为没有记录),它只是一个实现副作用

What you experience on Windows is not the expected behaviour (as it is not documented), it is just an implementation side effect.

showDialog()用于显示自定义对话框(例如,不是打开或保存对话框)。它有一个参数来指定批准按钮的文本。如果尚未使用 setDialogTitle()方法设置标题,则实现会任意选择使用批准按钮的文本作为Windows操作系统上的标题,但是在任何地方都没有记录并且你不应指望这个工作。

The showDialog() is used to display a custom dialog (e.g. not an Open nor Save dialog). It has a parameter to specify the text of the Approve button. If the title has not been set with the setDialogTitle() method, the implementation arbitrarily chooses to use the approve button's text as the title on Windows OS, however this is not documented anywhere and you should not count on this to work.

如果你想要自定义标题,请使用 setDialogTitle()。如果您需要自定义批准按钮文本,请使用 setApproveButtonText()。显然 showDialog()也会接受批准按钮的文本,在这种情况下,您不需要事先调用 setApproveButtonText()

If you want a custom title, use setDialogTitle(). If you want a custom approve button text, use setApproveButtonText(). Obviously showDialog() also takes the approve button's text in which case you do not need to call setApproveButtonText() prior.

如果您想要一个打开对话框,请使用 showOpenDialog()方法。如果需要保存对话框,请使用 showSaveDialog()。如果你想要一个自定义对话框,只能使用 showDialog()

If you want an Open dialog, use the showOpenDialog() method. If you want a Save dialog, use the showSaveDialog(). Only use showDialog() if you want a custom dialog.

这篇关于Mac OS X中是否存在使用JFileChooser.showDialog(Component,String)设置标题的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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