How to change text in JFileChooser?

In JFileChooser Java swing component I need to change all text elements (for translation):

File Name: (JLabel)

Files of type: (JLabel)

Cancel (JButton)

Unfortunately, there are no methods for this.

Can I do this?

Thank!

+3
source share
7 answers

Mark this post . This is pretty awkward but works.

+7
source

Java Swing components are fully capable of understanding internationalization. This article explains the details and shows an example of how this can be done.

+2
source

JFileChooser, JFileChooser locale ( JFileChooser#setLocale(Locale)) JFileChooser . , JFileChooser . , , , .

+1
UIManager.put("FileChooser.fileNameLabelText", "FileName");
UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles");
+1

showDialog() (, "" "" ). "". setDialogTitle(), Windows, , .

, setDialogTitle(). , , setApproveButtonText(). , showDialog() , setApproveButtonText() .

, showOpenDialog(). "", showSaveDialog(). showDialog() .

+1

JFileChooser@setLocale(Locale) , . Mac OSX, .

Mac OSX, , UIManager.getLookAndFeelDefaults().setDefaultLocale(Locale); , Java 8, Java 7!

, Look and Feel UIManager.getDefaults().setDefaultLocale(Locale); Aqua , . , AquaFileChooserUI.java protected void installStrings(JFileChooser paramJFileChooser) UIManager.getString() , installStrings(), , BasicFileChooserUI, protected void installStrings(JFileChooser) .

Aqua: UIManager.getString("FileChooser.cancelButtonText");

: UIManager.getString("FileChooser.cancelButtonText",l);

fileChooser.setLocale(Locale); - OSX.

0

, Fasimba/Icewalker DevX Java. 1 , . .

public void changeButtonText (Component c, String original, String change) {

   if (c instanceof JButton) {
       JButton b = (JButton) c;
       if (b.getText() != null && b.getText().equalsIgnoreCase(original))
           b.setText(change);
   } else if (c instanceof Container) {
        Container cont = (Container) c;
        for (int i = 0; i < cont.getComponents().length; i++) {
           changeButtonText (cont.getComponent(i), original, change);
        }
   }
}

:

// dirChooser is the JFileChooser instance
for (Component c : dirChooser.getComponents()) changeButtonText(c, "Cancel", "Don't do it!");

0
source

Source: https://habr.com/ru/post/1788962/


All Articles