I have achieved what I am trying to do, but I cannot help but think that there is a more efficient way ... let me illustrate.
In short, the question I'm asking is whether there is a way to determine when a component completed its initial rendering.
I have a JList that is connected to the DefaultListModel module and is drawn by a special render that extends DefaultListCellRenderer.
This JList intent is to “page” through the log file, filling out 2,500 items each time a new page is loaded. On my machine, it usually takes a few seconds to fully display the JList, which is not really a problem, because changing the cursor to the wait cursor would be acceptable, because it would give the user immediate feedback. Unfortunately, I cannot find an elegant way to find out when the initial rendering is complete.
Below is the code of my visualization tool, in it you will see that I am calculating the number of iterations on the renderer. If it is from 0 to N-20, the cursor changes to a wait cursor. Once the N-20 is reached, it will revert to the default cursor. As I mentioned, this works fine, but the solution really looks like a hack. I implemented ListDataListener from DefaultListModel and PropertyChangeListener from JList, but did not create the functionality I'm looking for.
public class MessageListRenderer extends DefaultListCellRenderer { private static final long serialVersionUID = 1L; String lineCountWidth = Integer.toString(Integer.toString(m_MaxLineCount).length()); @Override public Component getListCellRendererComponent(JList l, Object value, int index, boolean isSelected, boolean haveFocus) { JLabel retVal = (JLabel)super.getListCellRendererComponent(l, value, index, isSelected, haveFocus); retVal.setText(formatListBoxOutput((String)value, index));
All I do to fill the model is:
// reset the rendering counter this.renderCounter = 0; // Reset the message history and add all new values this.modelLogFileData.clear(); for (int i = 0; i < this.m_CurrentPage.getLines().size(); i++) this.modelLogFileData.addElement(this.m_CurrentPage.getLines().elementAt(i));