TextField Document listener

Hello, I have a JTextField and I have created a DocumentListener because I don't want to allow user to insert too many characters.
When he does, I get this exception "Attempt to mutate in notification". Could anyone help me? My code is this one:
    public class MyListener implements DocumentListener
        public void insertUpdate(DocumentEvent ev)
            Document doc=(Document)ev.getDocument();           
            if(isTooLong()==true)
                try
                    doc.remove(ev.getOffset(),ev.getLength());
                catch(Exception e)
                    System.out.println("Error " + e.getMessage());
                    System.exit(0);
        public void removeUpdate(DocumentEvent e)
        public void changedUpdate(DocumentEvent e) {
    }

I get this exception "Attempt to mutate in notification". You can't update the Document from a DocumentListener.
The latest recommendation on how to do this is to use a DocumentFilter. An exaple can be found in the Swing tutorial on "Using Text Components":
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

Similar Messages

  • Illegal state exception in Document Listener

    Hi folks,
    Iam getting the IllegalStateException when iam trying to update the document in the Document Listener.
    spec says iam not supposed to mutate the document in the document Listener.
    My requirement is that: when user types any java key word in JTextPane..I need to change it's color. I tried this in DocumentListener and CaretListener. But Iam getting following Exception:
    Exception occurred during event dispatching:
    java.lang.IllegalStateException: Attempt to mutate in notification
    at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:971)
    is there any alternative way to do this?
    thanks in advance!!
    -TSR

    Take the code that you are using to update the document and submit it to Swing to run later, like this:
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        // your code goes here

  • Using a Document Listener to update a text field

    Hi,
    Background:
    I need to retrieve a number from a card using a hand scanner. I'm currently using a jTextField1 in Netbeans to do this. When the number is input (the format is 6 digits, i.e. 123456) the rest of the form fields are filled in and updated automatically from an oracle database as it should. I have the database being checked as soon as the field reaches 6 characters (doc.getLength() == 6), It all works great.
    Problem:
    The problem comes in when I need to input a card that has a newer, different format of numbers and characters, i.e. **001234567**, it's more than 6 characters. I need only the 123456 substring to update the form, and the 7 substring to input later.
    What I tried:
    I'm using the combination of pattern matching and substring to get the 1234567 part only. I thought of using a hidden field on the form to input the numbers to and then set the text of jTextField1. I'm not sure this would work and seems like a hack anyways.
    Code:
            public void updateLog(DocumentEvent e, String action) {
            Document doc = (Document) e.getDocument();
            Integer docLength = doc.getLength();
            String isCardLegal = jTextField1.getText(); // getting card from textbox
            returnString Del = new returnString();
            String str = Del.getNewNumberFromCard(isCardLegal);
            System.out.println("str: "  +str);
            if (docLength == 6) {
              // see if number exists in database here
    public class returnString {
        public String getNewNumberFromCard(String oldString) {
            Pattern p = Pattern.compile("\\*");
            Matcher m = p.matcher(oldString);
            String newString = m.replaceAll("");
            // takes off leading zeros when using a new card
            // otherwise just returns the string as-is
            if (newString.length() == 9) {
                newString = newString.substring(2);
                return newString;
            } else {
                return newString;
    }Does anyone have a better way to do this? I hope I was clear in my explanation.
    Thank You for your help,
    Alan
    Edited by: shadow_coder on Oct 8, 2009 12:01 PM

    I really thank you for your help, I realize I wasn't clear because I wasn't sure about too many different things. I'll try it again:
    I need to use a hand scanner to input id cards having 2 different character sets. I now realize I can have the scanner insert a carriage return at the end of the scan, so I need to be able to detect this carriage return. I'm using a documentlistener to look at each character in the textfield. The character sets I need to use are 6 characters long, and an 11 character long set (including asterisks).
    Here is my SSCCE:
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.Document;
    public class exampleCase extends JFrame implements ActionListener {
        JTextField textField1;
        public exampleCase() {
            getContentPane().setLayout(new FlowLayout());
            textField1 = new JTextField(15);
            textField1.getDocument().addDocumentListener(new MyDocumentListener());
            textField1.getDocument().putProperty("name", "TextField");
            getContentPane().add(textField1);
            setSize(300, 170);
            setVisible(true);
        public static void main(String argv[]) {
            new exampleCase();
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        class MyDocumentListener implements DocumentListener {
            public void insertUpdate(DocumentEvent e) {
                updateLog(e, "inserted into ");
            public void removeUpdate(DocumentEvent e) {
                updateLog(e, "removed from ");
            public void changedUpdate(DocumentEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            public void updateLog(DocumentEvent e, String action) {
                String newline = "\n";
                Document doc = (Document) e.getDocument();
                int changeLength = e.getLength();
                System.out.println(
                        changeLength  +" character"+
                        ((changeLength == 1) ? " " : "s ")
                        action+  doc.getProperty("name")  +"."+  newline
                        "  Text length = "+  doc.getLength()  +newline);
               try {
                    String docCharacters = doc.getText(0, 2); // Exception when increased
                    System.out.println("Characters are: "+  docCharacters);
                    if (docCharacters.equals("\\r")) { // How to check for carriage return?
                        System.out.println("I'm Here, Yeeaaah!!");
                } catch (BadLocationException ex) {
                   System.out.println("Error Here, bad location" + ex);
    }When I increase the '2' to be able to handle the characters, I get javax.swing.text.BadLocationException: Invalid location can anyone tell me why? I'm not sure why it works when the number is at 2 but not others!
    The other issue is, what is the correct way to detect a carriage return? I was able to test this when the number above was at 2. This doesn't work.

  • Document Listener not working the way i would like

    Hello.
    I have this situation:
    A Jtable and a field of JTextfields that are populated by clicking on the JTable rows or manual inserction.
    All the JTextFields have a DocumentListener attached.
    When i click on a row, every JTextField that is populated fires a insertUpdate and a removeUpdate event(the 1st click fires only insertUpdate).
    What i want is to catch this events only when someone chances anything on a JTextField.
    Ex: I click on row5, it populates the info and i change the address field, if i lose the focus or if i click on other row, i need to present a popup saying "Save or Discard changes".
    Any ideas how i could implement this?

    When you click on a row in the table your code should
    be something like:
    textField.removeDocumentListener(...);
    textField.setText(...);
    textField.addDocumentListener(...);Now when a DocumentEvent is generated you know it is
    because the user changed the text, not just because a
    new row was selected.Is there a way to get the Listener associated, i tryed
    textfield.getDocument().removeDocumentListener(new MyDocumentListener())but the component didn't lost the listener.
    Message was edited by:
    noe.rocha

  • Document Listener for JTextArea in JTable

    I am trying to implement a DocumentListener for JTextArea in JTable, but its not happening.
    Can someone tell me what's wrong. SSCCE below.
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.Icon;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.UIManager;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.text.Document;
    public class MyTable_TextArea extends JTable {
         private DefaultTableModel defaultTableModel;
         private Object[][] dataArray;
         private Object[] columnNameArray;
         public final int TEXT_COLUMN = 0;     
         // column headers
         public static final String TEXT_COLUMN_HEADER = "Text";
         // text area
         TextFieldRenderer3 textFieldRenderer3;
          * constructor
          * @param variableNameArray
          * @param columnNameArray
         public MyTable_TextArea(Object[][] variableNameArray, Object[] columnNameArray) {
              this.dataArray = variableNameArray;
              this.columnNameArray = columnNameArray;
              defaultTableModel = new DefaultTableModel(variableNameArray, columnNameArray);
              this.setModel(defaultTableModel)     ;
              // text field
            textFieldRenderer3 = new TextFieldRenderer3();
              MyDocumentListener myListener = new MyDocumentListener();
              textFieldRenderer3.getDocument().addDocumentListener(myListener);
            TableColumn modelColumn = this.getColumnModel().getColumn(TEXT_COLUMN);
              modelColumn.setCellRenderer(textFieldRenderer3);
          * nested class
         class MyDocumentListener implements DocumentListener {
             String newline = "\n";
             public void insertUpdate(DocumentEvent e) {
                  System.out.println ("insert update");
                 updateLog(e, "inserted into");
             public void removeUpdate(DocumentEvent e) {
                  System.out.println ("remove update");
                 updateLog(e, "removed from");
             public void changedUpdate(DocumentEvent e) {
                 //Plain text components do not fire these events
             public void updateLog(DocumentEvent e, String action) {
                 Document doc = (Document)e.getDocument();
                 int changeLength = e.getLength();
                 textFieldRenderer3.append(
                     changeLength + " character" +
                     ((changeLength == 1) ? " " : "s ") +
                     action + doc.getProperty("name") + "." + newline +
                     "  Text length = " + doc.getLength() + newline);
          * @param args
         public static void main(String[] args) {
              try{
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception e){
                   e.printStackTrace();
             String[] columnNameArray = {
                       TEXT_COLUMN_HEADER,
                       "1",
                       "2",
              Object[][]  dataArray = {      {"", "", ""},      };
              final MyTable_TextArea panel = new MyTable_TextArea(dataArray, columnNameArray);
              final JFrame frame = new JFrame();
              frame.getContentPane().add(new JScrollPane(panel));
              frame.setTitle("My Table");
              frame.setPreferredSize(new Dimension(500, 200));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(300, 200);
              frame.pack();
              frame.setVisible(true);
    class TextFieldRenderer3 extends JTextArea implements TableCellRenderer {
         Icon defaultIcon;
         boolean isChecked = false;
         public TextFieldRenderer3() {
              System.out.println ("TextFieldRenderer()");
              setToolTipText("Double click to type");
         @Override
         public Component getTableCellRendererComponent(JTable table,
                   Object value,
                   boolean isSelected,
                   boolean hasFocus,
                   int row,
                   int column) {
              System.out.println ("TextFieldRenderer.getTableCellRendererComponent() row/column: " + row + "\t"+ column);
              return this;
    }

    I've implemented in the cell editor. I don't see how to get the value being typed (and nothing appears in the text area)
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.EventObject;
    import javax.swing.Icon;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextArea;
    import javax.swing.UIManager;
    import javax.swing.event.CellEditorListener;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.text.Document;
    public class MyTable_TextArea extends JTable {
         private DefaultTableModel defaultTableModel;
         private Object[][] dataArray;
         private Object[] columnNameArray;
         public final int TEXT_COLUMN = 0;     
         // column headers
         public static final String TEXT_COLUMN_HEADER = "Text";
         // text area
         TextAreaEditor textAreaEditor;
          * constructor
          * @param variableNameArray
          * @param columnNameArray
         public MyTable_TextArea(Object[][] variableNameArray, Object[] columnNameArray) {
              this.dataArray = variableNameArray;
              this.columnNameArray = columnNameArray;
              defaultTableModel = new DefaultTableModel(variableNameArray, columnNameArray);
              this.setModel(defaultTableModel)     ;
              // text field
            textAreaEditor = new TextAreaEditor();
              MyDocumentListener myListener = new MyDocumentListener();
              textAreaEditor.getDocument().addDocumentListener(myListener);
            TableColumn modelColumn = this.getColumnModel().getColumn(TEXT_COLUMN);
              modelColumn.setCellEditor(textAreaEditor);
          * nested class
         class MyDocumentListener implements DocumentListener {
             String newline = "\n";
             public void insertUpdate(DocumentEvent e) {
                  System.out.println ("insert update");
                 updateLog(e, "inserted into");
             public void removeUpdate(DocumentEvent e) {
                  System.out.println ("remove update");
                 updateLog(e, "removed from");
             public void changedUpdate(DocumentEvent e) {
                 //Plain text components do not fire these events
             public void updateLog(DocumentEvent e, String action) {
                 Document doc = (Document)e.getDocument();
                 int changeLength = e.getLength();
                 textAreaEditor.append(
                     changeLength + " character" +
                     ((changeLength == 1) ? " " : "s ") +
                     action + doc.getProperty("name") + "." + newline +
                     "  Text length = " + doc.getLength() + newline);
          * @param args
         public static void main(String[] args) {
              try{
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception e){
                   e.printStackTrace();
             String[] columnNameArray = {
                       TEXT_COLUMN_HEADER,
                       "1",
                       "2",
              Object[][]  dataArray = {      {"", "", ""},      };
              final MyTable_TextArea panel = new MyTable_TextArea(dataArray, columnNameArray);
              final JFrame frame = new JFrame();
              frame.getContentPane().add(new JScrollPane(panel));
              frame.setTitle("My Table");
              frame.setPreferredSize(new Dimension(500, 200));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(300, 200);
              frame.pack();
              frame.setVisible(true);
    class TextAreaEditor extends JTextArea implements TableCellEditor {
         Icon defaultIcon;
         boolean isChecked = false;
         public TextAreaEditor() {
              System.out.println ("TextAreaEditor()");
              setToolTipText("Double click to type");
         @Override
         public Component getTableCellEditorComponent(JTable arg0,
                   Object arg1,
                   boolean arg2,
                   int arg3,
                   int arg4) {
              System.out.println ("TextAreaEditor() arg1: " + arg1 + "arg2: " + arg2  + " arg3: " + arg3  + " arg4: " + arg4  );
              return null;
         @Override
         public void addCellEditorListener(CellEditorListener arg0) {
              System.out.println ("TextAreaEditor().addCellEditorListener");
         @Override
         public void cancelCellEditing() {
              System.out.println ("TextAreaEditor().cancelCellEditing");
         @Override
         public Object getCellEditorValue() {
              System.out.println ("TextAreaEditor().getCellEditorValue");
              return null;
         @Override
         public boolean isCellEditable(EventObject arg0) {
              System.out.println ("TextAreaEditor().isCellEditable");
              return true;
         @Override
         public void removeCellEditorListener(CellEditorListener arg0) {
              System.out.println ("TextAreaEditor().removeCellEditorListener");          
         @Override
         public boolean shouldSelectCell(EventObject arg0) {
              System.out.println ("TextAreaEditor().shouldSelectCell");
              return false;
         @Override
         public boolean stopCellEditing() {
              System.out.println ("TextAreaEditor().stopCellEditing");
              return false;
    }

  • How to insertString in document listener

    I always got java.lang.IllegalStateException: Attempt to mutate in notification.
    I do not want to extend defaultstyleddocument. is there any solution for it.
    thanks a lot.

    Hello,
    what do you want to achieve ? Offer some source-code.
    If you want your special behaviour for your document override its insertString method. For example if you want a maximum length try this:public void insertString(int offs, String str, AttributeSet a)
                        throws BadLocationException
         int length = getLength();
         if ((length += str.length()) > maxChar)
              //don't insert if current chars > max chars
              return;
         super.insertString(offs, str, a);
    }regards,
    Tim

  • Document listener can catch line return?

    I have the following DocumentListener (implemented in MyInputListener) in a JPanel where I process each character as it's typed in by the user from the insertUpdate() method. But the one character I can't seem to get is the enter key. It's like the JTextField is capturing that for itself and not passing this on to my DocumentListener.
    Anyone have ideas on how to get around that?
    myField = new JTextField();
    MyInputListener listener = new MyInputListener();
    myField.getDocument().addDocumentListener(listener);
    public class MyInputListener implements DocumentListener {
         public void insertUpdate(DocumentEvent de) {
              // never falls here or in any of the other xUpdate() methods.

    JTextField is designed to work with a single line of text, so it filters out linefeeds before any listeners get fired. If you're working with multiline text, you should be using a JTextArea, not a JTextField.

  • Desperate help need with Document Listener

    I'm working on a very cool freeware Java text editor, that is working beautifully, except for the code used to change the color of reserved words, etc, on the fly...
    At the moment, I use a documentlistener. When text is inserted, I need to color some of that text automatically. However, when I try to call setCharacterAttributes in DefaultStyledDocument, it causes a runtime exception, Illegal State Exception (Attempt to mutate in notification)>
    I understand how this exception is caused, but how do I get around it?

    Thanks for the replies. They were very helpful, and I have now managed to sort the problem, although in a different way that involves using the key listening class you can add to containers...
    The java editor is called j-Scribe, and is a text editor dedicated to java. I've designed it to be more user friendly than other text editors, with a useful interface. The code dispplay is all highlighted, and clicking on a brace collapses that section of code, to make larger classes easier to work through... There are also some nifty filemanagement windows, including a history pane similar to IE6, and one click access to all open files, and one click access to all of their save and close functions... There are wizards to automate creation of certain elements of code, and eventually a number of intelligent features will be added. The program makes extensive use of xml to store all of the information generated by the program.
    I'm working on the alpha version right now, for release in about two weeks. The beta will be out three - four weeks after that, and the release should be late September / early October time...
    If you're interested, e-mail me and I'll add you to the list for the alpha and beta test releases...
    [email protected]

  • Help jtextpane document listener

    public void PaneDocumentListener(final DocumentEvent e)
         SwingUtilities.invokeLater(new Runnable()
         public void run()
         Document doc=(Document)e.getDocument();
              try
    Label1.setText(JTPane.getText());
    JTPane.getText().replace("cplusplus","java");
              catch(Exception errorr)
              System.out.println(errorr);
    can anyone help me??
    it is supposed to change the word cplus2 become java
    but it is not working..
    once i typed the word "cplusplus" it doesnt changed to "java"
    but the label1.setText() method is working
    can anyone point my mistake out??

    public void PaneDocumentListener(final DocumentEvent e)
                   SwingUtilities.invokeLater(new Runnable()
                   public void run()
                   String s;
                   String a="";
                   Document doc=(Document)e.getDocument();
                        try
                        s=JTP.getText();
                        a=s.replace("cplusplus","java");
                        catch(Exception errorr)
                        System.out.println(errorr);
                        JTP.setText(a);
              }i did like this and it works, but my program become VERY irresponsive and slow..
    any1 knows why??
    thanks??
    Message was edited by:
    w32sysfie

  • JTable Document Listener for JTextField editor

    hello, how can I tell if removeUpdate in DocumentListener has been triggered by the user performing a delete in a JTextField or by the user cancelling a previous edit?
    example table
    | abc | def | ghi |<- user clicks in this cell which puts it in editmode
    | jkl | mno | pqr |<- user then clicks here which triggers removeUpdate for previous cell but how do I know this?
    Regards,
    b

    hello, how can I tell if removeUpdate in DocumentListener has been triggered by the user performing a delete in a JTextField or by the user cancelling a previous edit?
    example table
    | abc | def | ghi |<- user clicks in this cell which puts it in editmode
    | jkl | mno | pqr |<- user then clicks here which triggers removeUpdate for previous cell but how do I know this?
    Regards,
    b

  • Re: Problem regarding textfield

    [url http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html]How to Write a Document Listener
    As I understand the question you have 3 entry fields and 2 display fields. So I would add a DocumentListener to the 3 entry fields. Then when any other the fields change you will be notified and you can recalculate the value of the 2 display fields. Using a DocumentListener you don't force the user to press enter or tab to a new field as a DocumentEvent is fired for every character typed.
    If you only want to recalculate the display fields when the user is finished entering data in a text field then you could use a FocusListener or an ActionListener.

    Thanks for all informatiom cramcirk.
    Now I have further few questions to you....
    I am using 2 textfields for calculation of third text field.
    When I insert some thing in 1st textfield I get null pointer exception for textfield number 2.
    How and where I have to check the source like what we do in case of ActionEvent
    as ae.getSource() == btnLast where if source is btnLast then do follwing.
    Regards
    Rakesh

  • How do I listen for changes in a container's components?

    I have a JScrollPane that contains a JTextPane. I want any Container that can possibly contain my JScrollPane to be able to listen for changes in the JTextPane's Document.
    For example, at the moment I'm using a JTabbedPane to hold a number of my JScrollPanes and I want to alter the tab title when any associated JScrollPane-JTextPane-Document is updated.
    Any suggestions on how best to handle this?

    I would use a controller object that manages all your gui components (tabs, scrolls, documents, text panes). Your controller object can register as a listener to the appropriate component, and when it changes, update the title of a tab (or do whatever else) as appropriate.
    Never put business logic like this stuff inside the actual gui components. Create, layout, etc. all the gui components (and related components like Document) from another controller like object instead. It makes handling the various listener stuff like this much easier. Read up on MVC (model view controller) stuff for more info.
    As for the actual mechanics, you could get the document that is used in the JTextPane and register as a DocumentListener. As a document listener, you get notified of all changes that are made to that document.

  • App errors for some kind of PDF-documents

    Hello,
    we are getting java.lang.NullPointerExceptions for some PDF-documents
    to be Rights Management protected by using com.adobe.livecycle.rightsmanagement.RightsManagementService.applyPolicy()
    Client-side gets this exception:
        System.Web.Services.Protocols.SoapException: com.adobe.edc.sdk.SDKException: Error during the closing
                   of document listeners. -- Internal server error(error code bin: 1032, hex: 0x408)
    Part of the server-side stack trace is:
    2009-07-29 15:09:09,728 ERROR [com.adobe.idp.Document] DOCS001: Unexpected exception. Custom DocumentWriterEx.onDisconnect() throws: java.lang.NullPointerException.
    java.lang.NullPointerException
          at com.adobe.internal.pdftoolkit.pdf.document.PDFCosFactory.getUserData(PDFCosFactory.java:6 5)
          at com.adobe.internal.pdftoolkit.pdf.document.PDFCosFactory.getInstance(PDFCosFactory.java:2 18)
          at com.adobe.internal.pdftoolkit.pdf.document.PDFDocumentInfo.getInstance(PDFDocumentInfo.ja va:68)
          at com.adobe.internal.pdftoolkit.pdf.document.PDFDocument.getDocumentInfo(PDFDocument.java:4 63)
          at com.adobe.internal.pdftoolkit.services.xmp.DocumentMetadataImpl.commit(DocumentMetadataIm pl.java:1039)
          at com.adobe.internal.pdftoolkit.services.xmp.DocumentMetadataImpl.message(DocumentMetadataI mpl.java:233)
          at com.adobe.internal.pdftoolkit.pdf.document.listener.DocumentListenerRegistryBase.sendMess age(DocumentListenerRegistryBase.java:220)
          at com.adobe.internal.pdftoolkit.pdf.document.listener.GroupDocumentListener.message(GroupDo cumentListener.java:120)
          at com.adobe.internal.pdftoolkit.pdf.document.listener.DocumentListenerRegistryBase.sendMess age(DocumentListenerRegistryBase.java:220)
          at com.adobe.internal.pdftoolkit.pdf.document.PDFDocument.finish(PDFDocument.java:342)
          at com.adobe.pdfdocumentmanager.SharedPdfDocumentInternal$PDFCheckinImpl.checkinPDF(SharedPd fDocumentInternal.java:493)
          at com.adobe.pdfdocumentmanager.PDFDocumentVsDocumentCore$Data.getDoc(PDFDocumentVsDocumentC ore.java:333)
          at com.adobe.pdfdocumentmanager.SharedPdfDocumentInternal$Writer.write(SharedPdfDocumentInte rnal.java:673)
          at com.adobe.pdfdocumentmanager.SharedPdfDocumentInternal$Writer.onDisconnect(SharedPdfDocum entInternal.java:871)
          at com.adobe.pdfdocumentmanager.PDFDocumentVsDocumentCore$WriterProxy.onDisconnect(PDFDocume ntVsDocumentCore.java:249)
          at com.adobe.idp.DocumentCacheID.unregister(DocumentCacheID.java:73)
          at com.adobe.idp.Document.dispose(Document.java:2217)
          at com.adobe.pdfdocumentmanager.client.SharedPdfDocumentContext.releasePDFDocument(SharedPdf DocumentContext.java:233)
          at com.adobe.pdfdocumentmanager.client.SharedPdfDocumentContext.clear(SharedPdfDocumentConte xt.java:297)
          at com.adobe.pdfdocumentmanager.client.SharedPdfDocumentContext.exitScope(SharedPdfDocumentC ontext.java:222)
          at com.adobe.pdfdocumentmanager.client.SharedPdfDocumentContext.endScope(SharedPdfDocumentCo ntext.java:161)
          at com.adobe.livecycle.rightsmanagement.RightsManagementService.applyPolicy(RightsManagement Service.java:207)
          at com.adobe.livecycle.rightsmanagement.RightsManagementService.applyPolicy(RightsManagement Service.java:463)
    What might be the reason for those documents to get errors during
    Thanks for any hints!
    Dilettanto

    Thank you Steve,
    enclosed are my answers:
    1)  What versions are you using (Rights Management ES, Acrobat etc...)
          --> RightsManagement Server 8.2
    2)  Does this occur an ALL pdfs?  If not please postone that causes the error.
         --> No - this occurs only to some PDF-documents that come from external sources and that have been PDF-stamped by some
              external tool.    
              Other documents can be RightsManagement-protected just fine
              But how to tell, what part of those documents is the reason for the null-pointer-exception?
    3)  Can you successfully apply a policy manually using Acrobat Pro?
              will try this right now
    4)  Are you only trying to apply a policy or is it part of a larger process?
              Regarding LiveCycle Server, ApplyPolicy is the only action to be done
              We are using code based on the ApplyPolicy Sample

  • JCheckBox/Action Listener help

    Hey
    I'm trying to make an applet with two tabs, a PurchasePanel and a StorePanel, and have data altered in one of them affect the data in the other. On the StorePanel, the data is input infields and through a ButtonListener command it is stored as both a String in a text field on the StorePanel, and as a check box on the PurchasePanel. Now, from the PurchasePanel I need to make an ActionListener function that when the CheckBoxes are pressed, some data is added to another textfield, and when it is unchecked the data is removed. I'm not sure I implemented the actionlistener correctly as the buttonlistener and the actionlistener commands aren't recognizing variables from each other. Any help is appreciated.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.Container;
    import java.text.*;
    public class StorePanel extends JPanel
    private ArrayList compList;
    private PurchasePanel purchasePanel;
    private JLabel brandName, price, memory, cpuType, cpuSpeed, info;
    private JTextArea cpuInfo;
    private JTextField BTL, PTL, MTL, TTL, STL;
    private JPanel smallPanel, leftPanel, rightPanel, wholePanel;
    private JScrollPane scrollBox;
    public int counter = 0;
    public StorePanel(ArrayList compList, PurchasePanel pPanel)
    this.compList = compList;
    this.purchasePanel = pPanel;
    brandName = new JLabel("Brand Name ");
    price = new JLabel("Price");
    memory = new JLabel("Memory");
    cpuType = new JLabel("CPU Type");
    cpuSpeed = new JLabel("CPU Speed");
    BTL = new JTextField();
    PTL = new JTextField();
    MTL = new JTextField();
    TTL = new JTextField();
    STL = new JTextField();
    JPanel smallPanel = new JPanel();
    smallPanel.setLayout(new GridLayout(5,2));
    smallPanel.add(brandName);
    smallPanel.add(BTL);
    smallPanel.add(price);
    smallPanel.add(PTL);
    smallPanel.add(memory);
    smallPanel.add(MTL);
    smallPanel.add(cpuType);
    smallPanel.add(TTL);
    smallPanel.add(cpuSpeed);
    smallPanel.add(STL);
    // organize components here
    // here is an example
    JButton button1 = new JButton("Store");
    button1.setSize(1,1);
    button1.addActionListener(new ButtonListener());
    info = new JLabel("INFORMATION", SwingConstants.CENTER);
    leftPanel = new JPanel();
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(info,BorderLayout.NORTH);
    leftPanel.add(smallPanel,BorderLayout.CENTER);
    leftPanel.add(button1,BorderLayout.SOUTH);
    cpuInfo = new JTextArea("No Computer",19,27);
    scrollBox = new JScrollPane(cpuInfo);
    rightPanel = new JPanel();
    rightPanel.add(scrollBox);
    wholePanel = new JPanel();
    wholePanel.setLayout(new BorderLayout());
    wholePanel.add(leftPanel,BorderLayout.WEST);
    wholePanel.add(rightPanel,BorderLayout.EAST);
    this.add(wholePanel);
    private class ButtonListener implements ActionListener
         public void actionPerformed(ActionEvent event)
              String BN = BTL.getText();
              String P = PTL.getText();
              String M = MTL.getText();
              String CT = TTL.getText();
              String CS = STL.getText();
              String error = "";
              String enter = "";
              String computerString = "";
              int speed = 0;
              int memory = 0;
              double price = 0;
              String status = "Yes";
              String bPrice = "";
              JCheckBox computer;
              try
                   speed = Integer.parseInt(CS);
                   memory = Integer.parseInt(M);
                   price = Double.parseDouble(P);
              catch (NumberFormatException exception)
                   info.setText("Enter a number for Price, Memory, or Speed.");
                   info.setForeground(Color.red);
                   status = "No";
              if(BN.length() == 0 || P.length() == 0 || M.length() == 0 || CT.length() == 0 || CS.length() == 0)
                   error = "Please Enter All Fields.";
                   status = "Empty";
              if(status == "Yes" || status == "Empty")
              if(error == "Please Enter All Fields.")
                   info.setText(error);
                   info.setForeground(Color.red);
              else
                   DecimalFormat myFormatter = new DecimalFormat("0,000.00");
                   bPrice = myFormatter.format(price);
                   if(counter == 0)
                        cpuInfo.replaceRange("",0,11);
                   enter = "\nBrandName:\t\t" + BN + "\nCPU:\t\t" + CT + "," + speed
                                  + "HZ\nMemory:\t\t" + memory + "M\nprice:\t\t$" + bPrice + "\n";
                   info.setText("Computer Added.");
                   info.setForeground(Color.red);
                   cpuInfo.append(enter);
                   counter ++;
                   computer = new JCheckBox("BrandName:"+BN+"CPU:"+CT+","+speed+"HZMemory:"+memory+"Mprice:$"+bPrice);
                   computer.addItemListener(new PurchasePanel.CheckBoxListener());
                   purchasePanel.leftPane.add(computer);
                   compList.add(computer);
    public class PurchasePanel extends JPanel
    private ArrayList compList;
    private JLabel CTP, Filler;
    private JTextArea totalPrice;
    protected JPanel rightPane, leftPane;
    protected JSplitPane wholePane;
    private JScrollPane scrollPane;
    private JCheckBox checked;
    private double TP = 0.00;
    public PurchasePanel(ArrayList compList)
         this.compList = compList;
         // organize components for purchase panel
         CTP = new JLabel("Current Total Purchase");
         Filler = new JLabel(" ");
    totalPrice = new JTextArea("$" + TP,18,22);
    scrollPane = new JScrollPane(totalPrice);
         rightPane = new JPanel();
         rightPane.setLayout(new BorderLayout());
    rightPane.add(CTP, BorderLayout.CENTER);
         rightPane.add(scrollPane, BorderLayout.SOUTH);
         leftPane = new JPanel();
         leftPane.setLayout(new BoxLayout(leftPane, BoxLayout.Y_AXIS));
         leftPane.setSize(800,700);
         leftPane.add(Filler);
         wholePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane);
         this.add(wholePane);
    private class CheckBoxListener implements ItemListener
         public void itemStateChanged(ItemEvent event)
                   if(StorePanel.ButtonListener.computer.getStateChange() == ItemEvent.SELECTED)
                        TP = TP + 10.05;
    public class Assignment6 extends JApplet
    private int APPLET_WIDTH = 650, APPLET_HEIGHT = 350;
    private JTabbedPane tPane;
    private StorePanel storePanel;
    private PurchasePanel purchasePanel;
    private ArrayList computerList;
    //The method init initializes the Applet with a Pane with two tabs
    public void init()
         //list of computers to be used in every panel
         computerList = new ArrayList();
         //customer purchase panel uses the list of computers
         purchasePanel = new PurchasePanel(computerList);
         //store inventory panel uses the list of computers and also
         //established a connection with purchasePanel
    storePanel = new StorePanel(computerList, purchasePanel);
    //create a tabbed pane with two tabs
    tPane = new JTabbedPane();
    tPane.addTab("Store Inventory", storePanel);
    tPane.addTab("Customer Purchase", purchasePanel);
    getContentPane().add(tPane);
    setSize (APPLET_WIDTH, APPLET_HEIGHT); //set Applet size
    }

    If you pass along references to the appropriate panel to the Listeners, then they can update the right thing accordingly eg.
    // To enable the StorePanel to add/erase data from a textfield by listening to a checkbox in the PurchasePanel class
    // PurchasePanel class
    checked.addItemListener(new CheckBoxListener(storePanel));
    // CheckBoxListener class
    public void itemStateChanged(ItemEvent e) {
        // When checkbox checked
        if(checked)
            storePanel.writeToTextField("blahblah");
        else
            storePanel.writeToTextField("");
    }That was pseudocode of course! If you need the PurchasePanel to listen to the button in the StorePanel, you need to do the reverse.

  • Java TEXT PANE & DOCUMENT

    when i try to update the text associated with a document i get an exception "illegalstateexception"

    I have created a JTextPane & associated it with a Default Styled Document.I have added Document Listener to the Document.Now when i type text in the JTextPane at run time ,I get my insertUpdate event triggered.In that i am trying to change the attribute of some of the code to reflect color coding concept in my GUI project.But i get illegalStateException .

Maybe you are looking for

  • Correcting email address that adobe is trying to send file from

    I have asked this Q before with no resolution but I really need this fixed.  If I open a file that is in adobe reader or acrobat, etc.  When I click on the option to "send" it then brings up a black box a saying " [email protected]:  creating draft m

  • Importing audio files without slowing down site?

    Being new to mac and iweb, i have found that with my photo gallery web site that when i attach an audio file to play when a certain page is viewed that my site load time is dramatically slowed down. Anybody know how to speed it up?

  • # How to get the system AD Domain user login name in portal?

    when a system user use AD Domain method login the system. and then the user open the portal web application page, but not use AD Domain name login in portal page, that time ,I want to catch the user system login name show in portal page? I hava try t

  • Recurring directory errors in Time Machine backup

    I'll try to make this brief: Mac Pro 2 x 2.66 GHz Xeon 4 - 500 GB internal drives set up as 2 - striped 1 TB RAIDS OS X 10.7.3 For years, I have used Time Machine to backup RAID #1 to RAID #2 with no errors at all. Recently, backups have been failing

  • How can I use WM_CONCAT with DISTINCT in a stored provedure?

    Hi, I join three tables. For example one is for employees, other is for employee address, and the last one is for the cities of employees that work. I want to take the employee id, address city, and working cities. It is like the table below, but I w