nedjma
nedjma

Reputation: 21

Changing the default Windows language with Java application

Can I change the default language of my host system (Windows XP) with a Java application? If yes, how I can do it?

Upvotes: 2

Views: 800

Answers (2)

mdma
mdma

Reputation: 57707

You can set the default input language using the Windows SystemParametersInfo API.

BOOL WINAPI SystemParametersInfo(
  __in     UINT uiAction,
  __in     UINT uiParam,
  __inout  PVOID pvParam,
  __in     UINT fWinIni
);

Using JNA is much easier than using JNI. To invoke this API function in User32.dll using JNA, create an interface:

public interface User32 extends StdCallLibrary
{
   User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);

   bool SystemParametersInfo(int uiAction, int uiParam, int[] pInt, int fWinIni);
}

You determine the LCID of the language you want to change to. (Here's the list from MSDN.) For example, English is 0x409. An then use the LCID in the call to SystemParametersInfo:

int lcid = 0x409;
final int SPI_SETDEFAULTINPUTLANG = 90; 
User32.INSTANCE.SystemParamtersInfo(SPI_SETDEFAULTINPUTLANG, 0, new int[] { lcid }, 0);

And thenn your default input language has been changed!

Upvotes: 5

BalusC
BalusC

Reputation: 1108782

There are no builtin ways provided by Java SE API. I at least see nothing in the Desktop API. You'll need to grab OS-native API's. Forget Java for this bit, how exactly would you do this without Java? Once figured out, call the particular API using JNI in Java.

Upvotes: 0

Related Questions