I am trying to display a JTable that takes a LogRecord and shows the time at which the record was raised as well as the actual message. The message is supposed to be color-coded by the LogRecord's Level, so for instance, Level.Info is displayed as black, a warning is yellow, and severe is red.
The JTable is situated in a JScrollPane, which is part of a JInternalFrame, which is then housed in a JDesktopPane.
When I run my test program, the window for the JTable does pop up, but it is blank. If I manually drag and resize the window, the JTable appears, but the color coding is incorrect. The text is all colored yellow, when it should be red and yellow. I noticed that the final text color is dependent on the last LogRecord the table receives. So for example, the code currently passes a Warning as the last message, so the table text is all yellow. I tried passing Severe as the final message, and similarly the text was all red. I see why that happens. In TestFrame.java, there is a global Level variable that stores the level of the current LogRecord and colors the text accordingly. What seems to be happening is that all the messages are passed to the JTable before I manually resize the window, and once it becomes visible, that is when the JTable is actually constructed. As a result, the global Level variable will always represent the last message passed.
I hope that explanation all made sense so far. I've posted the two pieces of code below. TestFrame is the code for the actual JInternalFrame, and TestFrameTest is where I place the internal frame in a desktop pane and pass LogRecords.
> When I run my test program, the window for the JTable does pop up, but it is blank.
frame.setVisible(true) is in the wrong spot
> The text is all colored yellow,
you would need to associate a currentLevel with each value, otherwise when the last row is added, all is rendered again, based on the global 'currentLevel'
here's an example, using the renderer's getTableCellRenderComponent where the color is set based on each value I've changed a lot around - I don't have(or don't seem to have) some of the classes, but it should be simple enough to put back.