PlainDocument « JTextField « Java Swing Q&A





1. java: is the default document of a JTextField always a PlainDocument?    stackoverflow.com

Is this always true?

new JTextField().getDocument() instanceof PlainDocument
Because I have read many examples of PlainDocument where they always create a new PlainDocument and then assign it to a JTextField, e.g. here. ...

2. Limit use of comma onto JtextField with PlainDocument    forums.netbeans.org

I have extends PlainDocument and add to Jtextfield code: jtextfield.setDocument(NumericPlainDocument) code of NumericPlainDocument: public class JNumericFieldFilter extends PlainDocument { protected String acceptedChars = "0123456789,"; protected boolean negativeAccepted = false; public JNumericFieldFilter() ...

3. SWING JTextField (No "PlainDocument usage")    coderanch.com

import javax.swing.*; import java.awt.*; import javax.swing.text.*; class Testing extends JFrame { public Testing() { setLocation(400,300); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel jp = new JPanel(); JTextField tf = new JTextField(new PlainDocument(){ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException{ String newStr = new StringBuffer(getText(0,getLength())).insert(offs,str).toString(); if(newStr.length() > 10) { java.awt.Toolkit.getDefaultToolkit().beep(); return; } else super.insertString(offs, str, a);}},"",10); jp.add(tf); getContentPane().add(jp); pack(); } public static void main(String[] ...