Запуск потока Java с помощью Runnable открывает новое небольшое всплывающее окно для процесса. Как я могу избежать всплывающего окна? - PullRequest
0 голосов
/ 06 августа 2020

Я реализовал JTextArea, который действует как область, которая постоянно считывает вывод файла журнала из другого процесса и представляет его пользователю.

Вот пример моего кода:

class CustomOutputStream extends OutputStream {
    private JTextArea textArea;
     
    public CustomOutputStream(JTextArea textArea) {
        this.textArea = textArea;
    }
     
    @Override
    public void write(int b) throws IOException {
        // redirects data to the text area
        textArea.append(String.valueOf((char)b));
        // scrolls the text area to the end of data
        textArea.setCaretPosition(textArea.getDocument().getLength());
    }
}

class TextAreaLogProgram extends JFrame {
    /**
     * The text area which is used for displaying logging information.
     */
    private JTextArea textArea;
     
    public TextAreaLogProgram() {
        // the formEnvironment is part of install4j
        textArea = ((JTextArea)formEnvironment.getFormComponentById("3341").getConfigurationObject());
        
        PrintStream printStream = new PrintStream(new CustomOutputStream(textArea));
 
         printLog();
         
    }
     
    /**
     * Prints log statements in a thread
     */
    private void printLog() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
            
                while (true) {
                    // A whole lot of regex matching is done here to present the info that we want
                    // to the user and once we reach the end I break
                        break;
                    }
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        });
        thread.start();
    }
 }

// Start the whole thing by making it visible.It's hidden by default
new TextAreaLogProgram().setVisible(true);

Теперь приведенный выше код добавляет небольшое «раздражающее» всплывающее окно в верхнем левом углу, в котором нет содержимого, и только обычные кнопки «Развернуть» и «Закрыть», прикрепленные к нему со значком Java с левой стороны. Вот так:

раздражающее всплывающее окно

Есть ли способ делать все, что я делаю прямо сейчас, без этого всплывающего окна?

Заранее всем спасибо .

...