Problems and solutions for UI collapse when inputting Japanese in swing

Introduction

Swing related bugs these days? I was suffering from.

1.png

For example, suppose you prepare JTextComponent components such as JTextField and JTextArea like this. There is no particular difference in the amount of half-width alphanumeric characters entered, but as soon as I entered Japanese,

2.png $ \ Huge {na-n-na-n-su-ka-ko-re} $ </ font>

There are also some bugs.

When I googled, I found a solution that I could just keep hitting repaint () on the window using ʻInputMethodListener, so while I wasn't minimizing the frame, I found a solution after entering full-width characters in the component and then whilePrepared a bug fix class to keep hittingrepaint ()` of the frame with.

Bug fix class

python


final class SwingPaintBugFix extends Thread {
    private Window w;
    private boolean running = true;

    private static SwingPaintBugFix bugfix = new SwingPaintBugFix();

    private SwingPaintBugFix() {}

    private SwingPaintBugFix(Window w) {
        this.w = w;
    }

    public static void of(JTextComponent txtComp, Window w) {
        w.addWindowListener(new WindowAdapter() {
            @Override public void windowIconified(WindowEvent e) {
                bugfix.stopRunning();
            }
            @Override public void windowDeiconified(WindowEvent e) {
                bugfix = new SwingPaintBugFix(w);
                bugfix.start();
            }
        });
        txtComp.addInputMethodListener(new InputMethodListener() {
            @Override public void inputMethodTextChanged(InputMethodEvent e) {
                //Receive double-byte characters
                bugfix.stopRunning();
                bugfix = new SwingPaintBugFix(w);
                bugfix.start();
            }
            @Override public void caretPositionChanged(InputMethodEvent e) {}
        });
        txtComp.addKeyListener(new KeyAdapter() {
            //Receive half-width characters
            @Override public void keyTyped(KeyEvent e) {}
        });
    }

    @Override public void start() {
        new Thread(this).start();
    }

    @Override public void run() {
        while (running) {
            ((Component) w).repaint();
        }
    }

    private void stopRunning() {
        running = false;
    }
}

However, I cannot deny the act of constantly executing the process while while, and it takes time to apply the bug fix class to all JTextComponent components, so I decided to search for a drastic solution.

Cause investigation

For the time being, it doesn't heal even if I restart it several times.

You can't update to the latest version while checking if there are any problems with Windows Update.

Though I thought "Amendo", I couldn't help it, so I went to safe mode. Since I confirmed that the above bug does not occur in safe mode, I will refrain from "background process" and "service" and return to normal startup.

"It's not this, it's not this ...", finish the tasks other than safe mode one by one from the task manager, and finally identify the cause!

3.png

It seems that the sound utility called "Nahimic Service" was the culprit. I tried stopping it and the bug was fixed. Looking at Gugu, it seems that this guy is competing in various ways other than UI related.

... It didn't make sense to create a bug fix class.

Recommended Posts

Problems and solutions for UI collapse when inputting Japanese in swing
Problems and solutions while creating index.html.erb in RubyOnRails 4 on Windows 10
Difference between byCharWrapping and byWordWrapping of UI Label in Japanese display
Errors and solutions and reference articles that occurred when putting Heroku in Vagrant