L&F中String键的位置

Java中有几个组件具有预定义的外观和自动打印在其上的文本字符串。 例子是JFileChooser。

此外,当您尝试在JFileChooser中进行非法重命名时,会弹出一个JDialog(或JOptionPane)…

在什么* .java文件中可以串起代表那些键的键,以及它们在哪里得到它们的值?

我说的是Nimbus L&F ……我找不到它们在Nimbus和Synth中(这并不意味着它们不存在)……我确实在BasicFileChooser中找到了JFileChooser字符串。

一句话:我正在翻译我的程序而且我不想要任何惊喜,所以我想知道哪些组件有预定义的字符串以及在哪里找到它们,从上面特别是JDialog ……

编辑:我找到了BasicFileChooserUI,这是方法之一:

protected void installStrings(JFileChooser fc) { Locale l = fc.getLocale(); newFolderErrorText = UIManager.getString("FileChooser.newFolderErrorText",l); newFolderErrorSeparator = UIManager.getString("FileChooser.newFolderErrorSeparator",l); newFolderParentDoesntExistTitleText = UIManager.getString("FileChooser.newFolderParentDoesntExistTitleText", l); newFolderParentDoesntExistText = UIManager.getString("FileChooser.newFolderParentDoesntExistText", l); fileDescriptionText = UIManager.getString("FileChooser.fileDescriptionText",l); directoryDescriptionText = UIManager.getString("FileChooser.directoryDescriptionText",l); saveButtonText = UIManager.getString("FileChooser.saveButtonText",l); openButtonText = UIManager.getString("FileChooser.openButtonText",l); saveDialogTitleText = UIManager.getString("FileChooser.saveDialogTitleText",l); openDialogTitleText = UIManager.getString("FileChooser.openDialogTitleText",l); cancelButtonText = UIManager.getString("FileChooser.cancelButtonText",l); updateButtonText = UIManager.getString("FileChooser.updateButtonText",l); helpButtonText = UIManager.getString("FileChooser.helpButtonText",l); directoryOpenButtonText = UIManager.getString("FileChooser.directoryOpenButtonText",l); saveButtonMnemonic = getMnemonic("FileChooser.saveButtonMnemonic", l); openButtonMnemonic = getMnemonic("FileChooser.openButtonMnemonic", l); cancelButtonMnemonic = getMnemonic("FileChooser.cancelButtonMnemonic", l); updateButtonMnemonic = getMnemonic("FileChooser.updateButtonMnemonic", l); helpButtonMnemonic = getMnemonic("FileChooser.helpButtonMnemonic", l); directoryOpenButtonMnemonic = getMnemonic("FileChooser.directoryOpenButtonMnemonic", l); saveButtonToolTipText = UIManager.getString("FileChooser.saveButtonToolTipText",l); openButtonToolTipText = UIManager.getString("FileChooser.openButtonToolTipText",l); cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText",l); updateButtonToolTipText = UIManager.getString("FileChooser.updateButtonToolTipText",l); helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText",l); directoryOpenButtonToolTipText = UIManager.getString("FileChooser.directoryOpenButtonToolTipText",l); } 

我想知道从哪里来的getString("FileChooser.updateButtonText",l)方法拉出字符串…我试着找它,但我没有运气…另外,我知道JFileChooser中有一些字符串未在BasicFileChooserUI.java中定义…

你要改变哪一个,但我现在不知道答案

在此处输入图像描述

DYM ???

在看:

文件名:

文件类型:

 import java.io.File; import javax.swing.*; import javax.swing.filechooser.FileFilter; class ChooserFilterTest { public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { String[] properties = {"os.name", "java.version", "java.vm.version", "java.vendor"}; for (String property : properties) { System.out.println(property + ": " + System.getProperty(property)); } JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(null); jfc.addChoosableFileFilter(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".obj"); } @Override public String getDescription() { return "Wavefront OBJ (*.obj)"; } @Override public String toString() { return getDescription(); } }); int result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); System.out.println("Displayed description (Metal): " + (result == JOptionPane.YES_OPTION)); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(jfc); } catch (Exception e) { e.printStackTrace(); } jfc.showOpenDialog(null); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); System.out.println("Displayed description (System): " + (result == JOptionPane.YES_OPTION)); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); System.out.println("Displayed description (Metal): " + (result == JOptionPane.YES_OPTION)); try { for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); SwingUtilities.updateComponentTreeUI(jfc); break; } } } catch (ClassNotFoundException ex) { } catch (InstantiationException ex) { } catch (IllegalAccessException ex) { } catch (javax.swing.UnsupportedLookAndFeelException ex) { } jfc.showOpenDialog(null); result = JOptionPane.showConfirmDialog(null, "Description was 'All Files'?"); System.out.println("Displayed description (System): " + (result == JOptionPane.YES_OPTION)); } }; SwingUtilities.invokeLater(r); } private ChooserFilterTest() { } } 

你想要这个吗?

在此处输入图像描述

来自代码

 import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.*; import javax.swing.plaf.metal.MetalButtonUI; public class CrazyFileChooser { public static void main(String[] args) { try { for (UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { } catch (InstantiationException ex) { } catch (IllegalAccessException ex) { } catch (javax.swing.UnsupportedLookAndFeelException ex) { } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new CrazyFileChooser().makeUI(); } }); } public void makeUI() { JFileChooser chooser = new JFileChooser(); for (AbstractButton button : SwingUtils.getDescendantsOfType(AbstractButton.class, chooser)) { button.setUI(new XORButtonUI()); button.setForeground(Color.GREEN); } for (JList list : SwingUtils.getDescendantsOfType(JList.class, chooser)) { list.setBackground(Color.PINK); } JTextField jTextField = SwingUtils.getDescendantOfType(JTextField.class, chooser, "Text", ""); jTextField.setEditable(false); for (JLabel label : SwingUtils.getDescendantsOfType(JLabel.class, chooser)) { label.setFont(new Font("Dialog", Font.ITALIC, 18)); label.setForeground(Color.RED); } chooser.showOpenDialog(null); } } class XORButtonUI extends MetalButtonUI { @Override public void paint(Graphics g, JComponent c) { g.setXORMode(Color.YELLOW); super.paint(g, c); } } 

基于代码Swing Utils ,由顶级Swing大师之一Darryl Burke(曾经告诉我们,付钱给我编程,是如何支付一个小孩舔冰淇淋)

许多此类用户界面元素已针对受支持的语言进行了本地化,如JDK 6和JRE 6支持的语言环境:用户界面翻译中所示

附录:另请参阅国际化:了解Java平台中的区域设置 。 未指定UIManager.getLookAndFeelDefaults()获取L&F默认值的方式; 不支持更改源数据。 返回的Map找到的属性的(非本地化)名称可用于覆盖默认值。 如“ 如何编写自定义外观”中所述,源文本存储在每个L&F和每个受支持的区域设置的属性文件中。 QuaQua就是一个例子。 例如,在我的平台上, com.apple.laf.AquaLookAndFeel的英文字符串就在

 $ JAVA_HOME /资源/ English.lproj / aqua.properties

警告:

 #读入此文件时,将字符串放入 
 #defaults表。 这是当前的实现细节
 #Winging的工作。 不要依赖于此。 这可能会改变
 #Wining的未来版本,因为我们改进了本地化支持。

另请参阅如何为默认情况下不支持的区域设置向JFileChooser添加本地化

这些键由Swing PLAF资源包提供,您可以在JDK源中找到它们。 见例如:

相邻包文件提供非英语语言的字符串值。

您只需为所需的人类语言创建一个文件并将其放在类路径的任何位置,就可以向这些系列中的任何一个添加一个包。 .java和.properties格式的捆绑包同样运行良好,但.java格式可能稍微更符合Unicode …

记住,直接向com.sun包添加内容可能会违反Java许可证,这可能是件好事。 因此,为了安全起见,将额外资源移至您自己的软件包并将其注册到UIManager可能是明智之举:

 UIManager.getDefaults().addResourceBundle("mypackage.swing.plaf.basic.resources.basic"); 

至于Nimbus,我没有找到任何特殊资源,所以选择“基本”可以完成工作……