Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get JScrollPane to Update during long process
    primarykey
    data
    text
    <p>I have a JScrollPane which contains a JTextArea object. In this particular application, the JTextArea is serving as a "process console" so that someone can see what is happening with a long-running process. My code looks like this:</p> <pre><code>JTextArea console; ... // Initializes the console panel, including creation of the JTextArea and JScrollPane private void initializePanel() { JPanel consolePanel = new JPanel(); ... console = new JTextArea(); console.setEnabled(false); textAreaScrollPane = new JScrollPane(console); ... } // Appends an incoming message to the console @Override public void update(Observable observable, Object consoleMessage) { console.append(consoleMessage + "\n"); console.update(console.getGraphics()); } </code></pre> <p>The problem I am running into is that my JScrollPane doesn't start with a scroll bar. As text gets appended to the underlying JTextArea, it goes off the bottom of the JScrollPane. Unfortunately, the scroll bar doesn't appear until the long-running process is complete. At that point, the scroll bar suddenly appears and the view jumps to they very end of the JTextArea.</p> <p>As such, the application looks like it is frozen as further messages are outside of the current viewport of the JScrollPane.</p> <p>I have tried different combinations of code to try to get the JSrollPane to repaint every time a message is written to it, but no such luck. The JTextArea gets the messages and they are printed immediately upon receipt - it's really the JScrollPane not adding the scroll bar right away that is being problematic.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload