private void initListeners() {

        // If ximEnabled is true, enable/disable Japanese input on focus gained/lost.
        addFocusListener(new FocusListener() {
            // NOTE only works in japanese environment.
            // See
            // <a href="http://java-house.jp/ml/archive/j-h-b/024510.html">JHB:24510</a>
            // <a href="http://java-house.jp/ml/archive/j-h-b/024682.html">JHB:24682</a>

            public void focusGained(FocusEvent e) {
                if (SystemEnvironment.isWindows()) {
                    if (ximEnabled) {
                        InputContext ic = getInputContext();
                        if (ic != null) {
                            ic.setCharacterSubsets(new Character.Subset[]{InputSubset.KANJI});
                            ic.selectInputMethod(Locale.JAPANESE);
                        }
                    } else {
                        InputContext ic = getInputContext();
                        if (ic != null) {
                            ic.setCharacterSubsets(null);
                            ic.endComposition();
                            ic.selectInputMethod(Locale.ENGLISH);
                        }
                    }
                }
            }

            public void focusLost(FocusEvent e) {
                if (SystemEnvironment.isWindows()) {
                    InputContext ic = getInputContext();
                    if (ic != null) {
                        ic.setCharacterSubsets(null);
                        ic.endComposition();
                        ic.selectInputMethod(Locale.ENGLISH);
                    }
                }
            }
        });

        // When this component hides a button under itself, propagete mouse click to the button.
        addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                Component source = (Component) e.getSource();
                Point p = e.getPoint();
                Container parent = source.getParent();
                for (int i = 0, n = parent.getComponentCount(); i < n; i++) {
                    Component c = parent.getComponent(i);
                    if (c instanceof AbstractButton && c.contains(SwingUtilities.convertPoint(source, p, c))) {
                        AbstractButton button = (AbstractButton) c;
                        button.setVisible(false);
                        button.doClick();
                    }
                }
            }
        });
    }