setEditable to JEditorPane

Reply

Join Date: Sep 2009
Posts: 13
Reputation: topest1 is an unknown quantity at this point 
Solved Threads: 0
topest1 topest1 is offline Offline
Newbie Poster

setEditable to JEditorPane

 
0
  #1
29 Days Ago
Hello All,

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

  1.  
  2. public void appendText(String text)
  3. {
  4.  
  5. displayChats.replaceSelection("\n"+text);
  6. displayChats.setCaretPosition(displayChats.getDocument().getLength()); //Scroll to bottom
  7.  
  8. }


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:
  1.  
  2. public void appendText(String text)//throws NullPointerException
  3. {
  4. displayChats.setEditable(true);
  5. displayChats.replaceSelection("\n"+text);
  6. displayChats.setCaretPosition(displayChats.getDocument().getLength());
  7. displayChats.setEditable(false);
  8. }

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)
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC