Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4536

Re: Problem with Document

From "Sigfried" <sigfried@THRWHITE.remove-dii-this>
Subject Re: Problem with Document
Message-ID <4938dfec$0$922$ba4acef3@news.orange.fr> (permalink)
Newsgroups comp.lang.java.gui
References <0616c9f0-a234-4877-bc56-8977a61b921e@w24g2000prd.googlegroups.com>
Date 2011-04-27 15:51 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
mick.heywood@gmail.com a ocrit :
> Hi there,
> 
> I'm trying to monitor changes to a JTextPane.  But I'm a bit stumped
> by the DocumentEvent.GetChange method.  No matter what element I pass
> to it it returns null.  The code has gotten a bit out of hand, but my
> last act of desperation was the following:
> 
>                 doc.addDocumentListener(new DocumentListener() {
>                     public void changedUpdate(DocumentEvent e) {
>                         logChange(e);
>                     }
> 
>                     public void insertUpdate(DocumentEvent e) {
>                         logChange(e);
>                     }
> 
>                     public void removeUpdate(DocumentEvent e) {
>                         logChange(e);
>                     }
> 
>                     private void logChange(DocumentEvent e) {
>                         if (e.getDocument() instanceof
> DefaultStyledDocument) {
>                             try {
>                                 DefaultStyledDocument doc =
> (DefaultStyledDocument)e.getDocument();
>                                 ArrayList<Element> els = new
> ArrayList<Element>();
>                                 GetAllElements(doc, els);
>                                 DocumentEvent.ElementChange chg =
> null;
>                                 for (Element elem : els) {
>                                     chg = e.getChange(elem);
>                                     if (chg != null) {
>                                         s.append("Found One!!" +
> elem.getName());
>                                         break;
>                                     }
>                                 }
>                             } catch (Exception ex) {
>                                 LogTextArea.append(ex.getMessage());
>                             }
>                         }
>                     }
>                 });
> 
> Needless to say the words "Found One!!" are never appended to s.  I
> really have no idea what I need to do to get hold of the
> DocumentEvent.ElementChange object.  Any ideas?

I can only suggest you to look at the DocumentEvent from a java debugger 
and see what's in it.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar


Thread

Problem with DocumentEven "mick.heywood" <mick.heywood@THRWHITE.remove-dii-this> - 2011-04-27 15:51 +0000
  Re: Problem with Document "Sigfried" <sigfried@THRWHITE.remove-dii-this> - 2011-04-27 15:51 +0000

csiph-web