I recently wanted to redirect the output of Log4j to a JTextPane, so as to output messages to the JTextPane using a different color depending on the severity.
I spent some time searching for information and I quickly put together a small example. The following screenshot shows the output.
[ad#half_banner_inline]
This is being very useful…
Thanks a lot….
Hi,
Thanks a lot for this example,very useful
but i need more more enhancement,when you are writing any of the log i.e warn ,error to textpane but log should not one liner than I want when i print log to textpane ,one by one line should be print,but here all logs are printed at the end.
to generate above scenario add a for loop in any of the button’s actionlistener with thread sleep.
exmaple
jButton2.addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent e)
{
for(int i=1; i<3;i++)
{
MainLogger.logWarn("This is a warning!!");
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}