return new PlainDocument() { public void insertString(int offset, String str, AttributeSet a) throws BadLocationException { if (str != null && str.indexOf('\n') == -1) super.insertString(offset, str, a); } };
return new PlainDocument();
  protected Document createDefaultModel()  {    // subclassed to swallow newlines    return new PlainDocument()    {      public void insertString(int offset, String str, AttributeSet a)          throws BadLocationException      {        if (str != null && str.indexOf('\n') == -1)          super.insertString(offset, str, a);      }    };  }