Recently I had to develop a small demo application for one of the leading newspapers in Bangladesh. I decided to localize my application and see all messages in Bangla. Searching Google I came across this article “Internationalization for Swing standard components”. This set me off in the right direction. However, there were some little tweaks I had to perform to get Bangla working. Firstly I had to set the font for the components user in JFileChooser.
final Font FONT_SOLAIMAN_LIPI = new Font("SolaimanLipi", Font.PLAIN, 15);
final FontUIResource eFontUIResource = new FontUIResource(FONT_SOLAIMAN_LIPI);
UIManager.put("Button.font", eFontUIResource);
UIManager.put("ToolTip.font", eFontUIResource);
UIManager.put("Label.font", eFontUIResource);
UIManager.put("EditorPane.font", eFontUIResource);
UIManager.put("TableHeader.font", eFontUIResource);
Next I had to set message values for properties as mentioned in Adrian's blog. However I had to set a couple of extra properties also
UIManager.put("FileChooser.directoryOpenButtonText");
UIManager.put("FileChooser.directoryOpenButtonToolTipText");
Finally there was this trouble of changing the tooltip for the home directory. The default JFileChooser implementation sets the tooltip to the name of the home directory which in my case (as will be in most cases :) ) was in english. So I had to end up writing a small visitor that would find the home folder button and reset the tooltip of the button as follows:
final String eHomeFolderName = eFileChooser.getFileSystemView().getHomeDirectory().getName();
MySwingComponentVisitor eVisitor = new MySwingComponentVisitor(eFileChooser, JButton.class) {
@Override
public boolean onComponentVisited(JComponent pVisitedComponent) {
JButton eButtonComponent = (JButton) pVisitedComponent;
if (eHomeFolderName.equals(eButtonComponent.getToolTipText())) {
eButtonComponent.setToolTipText(
getLocalizedMessage("homeFolderToolTipText"));
return STOP_VISITING;
}
return CONTINUE_VISITING;
}
};
eVisitor.visitComponents();
And the results were just so pleasing. A JFileChooser almost entirely in Bangla. Below are images showing how the JFileChooser transformed :)
Thursday, March 6, 2008
Internationalize Swing's JFileChooser in Unicode (Bangla)
Posted by Shams at 12:40
Labels: Bangla , Bengali , i18n , internationalization , JFileChooser , Unicode
Subscribe to:
Post Comments
(
Atom
)
5 comments :
Post a Comment
great tips and good work.
I used the ideas which you and the earlier linked page discuss to make
a similar JFileChooser which can switch between different languages as selected by the user. It works a treat.
One remaining problem, when I right click on the Dialog I get a pop up window - in English :-(
and I don't know what keys to set to change the text in the pop up
any ideas?
You need to do the following:
// Set the fonts for the menu and items
UIManager.put("Menu.font", eFontUIResource);
UIManager.put("CheckBoxMenuItem.font", eFontUIResource);
UIManager.put("RadioButtonMenuItem.font", eFontUIResource);
UIManager.put("MenuItem.font", eFontUIResource);
// And also set the label texts for
FileChooser.viewMenuLabelText
FileChooser.refreshActionLabelText
FileChooser.newFolderActionLabelText
FileChooser.listViewActionLabelText
FileChooser.detailsViewActionLabelText
And you should be able to see your popup in your language too :)
The following link should come in handy:
http://home.tiscali.nl/~bmc88/java/sbook/061.html#radiobuttonmenuitem
Hope it helps.
I have a problem that I wanna to use bangla font in JAVA like Jbuilder4 software(My current project is English to Bangla Dictionary) I can show the E2E but It's impossible to show the Bangla font or type in the JAVA. So how can I add BAngla font or word in JAVA at least to show the word meaning.
One thing If I have to Use UNICODE so how the procedure or implementation pls pls pls show me as soon as possible also with Coding...
My Contacts no 01671118854
And 01721051738
Masud &&& Sajjad
Hi Masud,
The nice thing about unicode and java is that you don;t have to do anything special. Just ensure your String in valid Bangla unicode.
In my case, I was using MS Indic IME to allow phonetic typing of Bangla text and reading that in using an XML file in Java.
Hope that helps.
UIManager.put("FileChooser.fileNameHeaderText", "Name");
or
UIManager.put("FileChooser.fileNameHeader.textAndMnemonic", "Name");
aren't working... Thanks!
Post a Comment