Thursday Jan 02, 2014

Google Translate in NetBeans IDE 7.4

Google Translate API is a paid service from the Google Cloud. Once you've set up your API key and billing information, you can use it in NetBeans IDE, too, of course.

Notice the from/to toolbar, where I've selected English/German: 

Then, above I right-click over a selection and choose "Translate", which I get back in German: 

The code is more or less the same as it was in my 2007 article on this topic:

However, in the meantime there's a REST API that can be used instead. I'm not using the REST API, still the same code as the above, though slightly changed because of changes in the Google Translate API:

public void actionPerformed(ActionEvent ev) {
    Language from = TranslatorPanel.from();
    Language to =;
    try {
        JTextComponent comp = EditorRegistry.lastFocusedComponent();
        String toChange = comp.getSelectedText();
        String text = TranslateV2.DEFAULT.execute(toChange, from, to);
    } catch (java.lang.NullPointerException ex1) {
    } catch (GoogleAPIException ex) {

All the source code of the above is here:


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« January 2014 »