Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to write accents (Spanish) properly in java based programs

I tried asking this in more general forums since it's not directly related to programming but I was unable to find an answer, so here I am.

When I try to type accented characters (like áéíóú) using the dead key method (the usual way in Spanish keyboards, press ´ and then the vowel to combine them) in every single Java based program, not made by me, like Netbeans, Eclipse or any .jar downloaded from the internet, it doesn't write the accent. When I press the ´ key twice it writes ´´´´ instead of ´´, which would be the normal behaviour.

I can "write" accented characters since I can copy them from the notepad, what I can't do is type them directly with the usual dead key method.

The input language shown in the language bar is Spanish, like everywhere else, and the layout of the keys is correct.

I tried reinstalling the JRE and looking for malware to no avail.

I'm using Windows XP and the JRE version is 1.6.0_26-b03, although it also didn't work in the preious version I had.

like image 632
QOI Avatar asked Jun 13 '11 08:06

QOI


2 Answers

Java code needs to be UTF-8. If you encode the characters using unicode \unnnn, you can have any unicode characters.

Here's how you would encode your example:

    String spanish = "\u00E1\u00E9\u00ED\u00F3\u00FA";
    System.out.println(spanish); // prints áéíóú

This works/compiles OK in Eclipse.

like image 53
Bohemian Avatar answered Nov 15 '22 00:11

Bohemian


Go into Control Panel -> Regional Options -> Languages -> [Details] -> [Language Bar] and toggle the 'Show Language Bar on Desktop' option so you can see if your Java programs are treating keyboard input differently to your other programs.

There are various ways to enter your accent keys using AltGr + various characters, or using ` as a dead key (i.e. press ` followed by a letter to compose an accented character.)

You can also try using Alt + the numeric codes on the keypad, which might take longer to type, but has got to be easier than translating everything to unicode code-points and inserting into strings using \u escape sequences.

There are various references for alt codes, here's just one plucked from Google: http://usefulshortcuts.com/alt-codes/spanish-alt-codes.php

like image 29
searlea Avatar answered Nov 14 '22 23:11

searlea