Search code examples
javaswingunixlayoutlocale

Double-byte system locale causes Swing component resizing


I'm working on a Swing app for Solaris, and I have a problem that shows up only when the system LANG variable is set to a double-byte language such as Korean. The problem is that components are being resized and this is messing up the layout of the app:

1) LANG set to Korean

last label doesn't fit

2) LANG set to English

all labels fit in the panel

Changing the Locale in the Java code itself does not affect the display (if LANG=English and Locale is set to Korean, everything is fine. If LANG=Korean and Locale is set to English, the issue happens).

Is this caused by the LayoutManager (I'm using BorderLayout)? Is there any way to prevent this from happening? So far the only workaround I can use is changing the system locale to english right before launching the app.

Here is some example code on what I'm doing:

Box container = Box.createVerticalBox();
container.add(label1);
container.add(label2);
container.add(label3);
container.add(label4);
container.add(label5);

Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
TitledBorder titledBorder = BorderFactory.createTitledBorder(border1,           LocalizationTools.getString("STR_1"));

Dimension lDim = new Dimension(550, 100);
mypanel = new JPanel(new BorderLayout());
mypanel.setPreferredSize(lDim);
mypanel.setMaximumSize(lDim);
mypanel.setMinimumSize(lDim);
mypanel.setBorder(titledBorder);
mypanel.add(container);

Here are some strings used in the example:

1) "\ud648 \ub514\ub809\ud1a0\ub9ac"

2) "\ubcc0\uacbd \uc2dc\uac04"

3) "\ub9c8\uc9c0\ub9c9 \uc791\uc5c5"


Solution

  • Here are a few things to try:

    • Ensure that you are calling pack() on the parent Window and not interfering with any component's preferred size.

    • Use a compound border, adding an EmptyBorder to your TitledBorder.

    • While debugging, add padding to the BorderLayout and use color for highlight.

    • Edit your question to include an sscce that exhibits the problem; a native user may see the problem (text cut-off at bottom) more clearly.