topest1 0 Newbie Poster

Hello All,

I am developing Chat Application, But facing a problem
in displaying Chat text

public void appendText(String text)
	{
		
		displayChats.replaceSelection("\n"+text);
		displayChats.setCaretPosition(displayChats.getDocument().getLength()); //Scroll to bottom
	
	}

Works fine while i append the text to JEditorPane(displayChats).

But when I use setEditable(false); (so that user cannot edit it).
then I need to again Enable the editing just before the replaceSelection
as shown below:

public void appendText(String text)//throws NullPointerException
	{
		displayChats.setEditable(true);
		displayChats.replaceSelection("\n"+text);
		displayChats.setCaretPosition(displayChats.getDocument().getLength());
		displayChats.setEditable(false);
	}

When i use this A following error occurs:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicTextUI$RootView.paint(Unknown Source)
        at javax.swing.plaf.basic.BasicTextUI.paintSafely(Unknown Source)
        at javax.swing.plaf.basic.BasicTextUI.paint(Unknown Source)
        at javax.swing.plaf.basic.BasicTextUI.update(Unknown Source)
        at javax.swing.JComponent.paintComponent(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(Unknown Source)
        at javax.swing.JComponent._paintImmediately(Unknown Source)
        at javax.swing.JComponent.paintImmediately(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)