JScrollPane picture list outside viewport

I have a list, each element of which has several things in it, including JProgressBarone that can update a lot. Each time one of the elements updates its own JProgressBar, it ListDataListenertries to scroll its visible range in the list using

/*
 * This makes the updating content item automatically scroll
 * into view if it is off the viewport.
 */
public void contentsChanged(final ListDataEvent evt) {
    if (!EventQueue.isDispatchThread()) {
        /**
          * Make sure the scrolling happens in the graphics "dispatch" thread.
          */
        EventQueue.invokeLater(new Runnable() {
            public void run()  {
               contentsChanged(evt);
            }
        });
    }
    if (playbackInProgress) {
        int index = evt.getIndex0();
        currentContentList.ensureIndexIsVisible(index);
    }
}

Please note that I am trying to make sure that scrolling is done in the send thread, since I thought the problem was that it scrolls while it is being repainted. And still, I still have a problem when, if something is really active, some elements of the list are painted outside the viewport, overwriting what is outside JScrollPane. Forcing an exposure event will recolor these things, but it is annoying.

- , , ?

+3
1

JList / , ? (: setDoubleBuffered(boolean aFlag))

, EDT. , , , ContentChanged , EDT. if ( if, runnable, , .

:

public void contentsChanged(final ListDataEvent evt)
{
    if (!EventQueue.isDispatchThread())
    {
        log.debug("Delegating contentsChanged(...) to EDT");

        EventQueue.invokeLater(new Runnable() 
        {
            public void run() 
            {
                contentsChanged(evt);
            }
        });
        // don't run ensureIndexIsVisible twice:
        return;
     }

     if (playbackInProgress)
     {
         int index = evt.getIndex0();
         currentContentList.ensureIndexIsVisible(index);
     }
}
+3

Source: https://habr.com/ru/post/1696566/


All Articles