5

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.

2 Answers 2

5

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.

2
  • This problem does not happen with my programs, it happens with every single program written in Java, even those not made by me, like Netbeans or Eclipse. For example if I try to write this comment: //Este método sirve para... I get: //Este metodo sirve para...
    – QOI
    Jun 13, 2011 at 9:17
  • for love of God, user does not know about \u00E1, so he or she puts á not unicode char how you gonna solve it then? May 28, 2014 at 5:23
1

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

5
  • @searlea It shows Spanish input, like everywhere else. "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.)" The dead key is the one i have problems with, it works properly everywhere else, and it used to work properly in java programs, too. What I usually do is type whatever I need on the notepad and then copy it to the java program, but it's really annoying and makes me waste a lot of time.
    – QOI
    Jun 13, 2011 at 9:54
  • Please enable the language bar while you're looking for the solution to your problem. You might find the input method is changing for Java programs - e.g. Your regular keyboard <-> US International keyboard for Java programs...
    – searlea
    Jun 13, 2011 at 10:17
  • There are 5 dead keys on a Spanish keyboard , ´, `, ¨, ~ and ^. None of them work properly, but only ´ and ¨ are actually used in Spanish. (apostrophe: ', spanish accent: ´)
    – QOI
    Jun 13, 2011 at 14:42
  • 1
    It looks like there are several relevant bugs in the Java bug database related to accents and dead keys. Might be worth trawling Oracle's Java bug database and/or logging an issue with them.
    – searlea
    Jun 13, 2011 at 14:43
  • Search the bug database (bugs.sun.com/bugdatabase) and you'll find several entries like bugs.sun.com/bugdatabase/view_bug.do?bug_id=4797332 (i.e. search for 'dead keys', or simply 'accent' etc.)
    – searlea
    Jun 13, 2011 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.