944,061 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 931
  • Java RSS
Nov 2nd, 2009
0

setEditable to JEditorPane

Expand Post »
Hello All,

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

Java Syntax (Toggle Plain 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:
Java Syntax (Toggle Plain Text)
  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)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
topest1 is offline Offline
19 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Hibernate Issue
Next Thread in Java Forum Timeline: Flash .swf files in Java application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC