documentfilter

DocumentFilter for negative and positive integer

守給你的承諾、 提交于 2021-01-28 08:21:07
问题 I know this is a common question, but I'm trying to create a TextField that only accept int numbers, and it's almost done, here's the code: Create textfield: nome = new JFormattedTextField(); nome.setHorizontalAlignment(SwingConstants.CENTER); nome.setColumns(2); DocumentFilter filtro = new FiltroNumero(); ((AbstractDocument) nome.getDocument()).setDocumentFilter(filtro); panel.add(nome); DocummentFilter: public class FiltroNumero extends DocumentFilter{ public void insertString

DocumentFilter: Why is replace() invoked and not insertString()?

北战南征 提交于 2020-12-30 09:47:18
问题 I've implemented a DocumentFilter subclass, and when I type text into the JTextComponent , the replace() method of the filter is invoked, and not insertString() (which is never invoked). Any idea why that is? 回答1: The insertString(...) method is invoked when you update the Document directly, by using the Document.insertString(...) method. The replace(...) method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes

DocumentFilter: Why is replace() invoked and not insertString()?

风格不统一 提交于 2020-12-30 09:46:38
问题 I've implemented a DocumentFilter subclass, and when I type text into the JTextComponent , the replace() method of the filter is invoked, and not insertString() (which is never invoked). Any idea why that is? 回答1: The insertString(...) method is invoked when you update the Document directly, by using the Document.insertString(...) method. The replace(...) method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes

Set DocumentFilter on JOptionPane

為{幸葍}努か 提交于 2020-01-24 13:05:07
问题 I'm using: String s = JOptionPane.showInputDialog(...); to get a response back from the user to a question; the dialog is set up to display a text field for the response. I'd like to limit the characters allowed in the response to alphanumeric and '_' only. Is it possible to install a DocumentFilter on the text field without implementing my own custom dialog from scratch? 回答1: Access the autocreated text field of JOptionPane is theoretically possible, but it's IMHO wrong way. Here is the

JTextField, using Document Filter to filter integers and periods

江枫思渺然 提交于 2020-01-24 05:10:06
问题 EDIT - added at then end of the post the answer we were able to achieve This is my first post in SO, so i hope i can ask everything right! I searched and didn't quite find a answer to my question despite similar questions being posted, so i hope this isn't a repost. This is what a i got, a small application that uses JTextField to receive user's input and on top of that i have a DocumentFilter so the user can only input integers and a period in order to receive values that represent weight.

How to set DocumentFilter with input length and range? e.g. 1-3 or 10-80

∥☆過路亽.° 提交于 2020-01-09 12:12:12
问题 I'm using DocumentFilter to restrict input as integer or decimal. And the code I post here is working well for that. Can anybody help me about how to restrict the input length or range in the given code? Thanks!! class MyIntFilter extends DocumentFilter { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb

How to set DocumentFilter with input length and range? e.g. 1-3 or 10-80

我只是一个虾纸丫 提交于 2020-01-09 12:04:28
问题 I'm using DocumentFilter to restrict input as integer or decimal. And the code I post here is working well for that. Can anybody help me about how to restrict the input length or range in the given code? Thanks!! class MyIntFilter extends DocumentFilter { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb

CellEditor with DocumentFilter never get called

强颜欢笑 提交于 2020-01-02 18:38:45
问题 I can't get this CellEditor with a DocumentFilter to work as i want. When i typed in the only editable column, insertString from PlainDocument is never called and documentFilter neither. I think im not overriding something correctly but i can't figured out. I made this Minimal, Complete, Tested and Readable example //TODO include imports public class Test { private static final int EDITABLE_COLUMN = 1; private final TableCellEditor cellEditor; private final JTextField textfield; private final

what should I do when DocumentFilter not listening for changes?

百般思念 提交于 2019-12-24 14:43:07
问题 Hi I have the following code : AbstractDocument d = (AbstractDocument)editorText.getDocument(); d.setDocumentFilter(new myFilter()); where editorText is a JTextArea. and my DocumentFiler is defined as follows : private class myFilter extends DocumentFilter{ public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr){ System.out.print("insert invoked"); try { super.insertString(fb, offset, "; You inserted the string: "+string, attr); } catch

Regex for DocumentFilter to match all decimal number but also number with just a decimal at the end

一笑奈何 提交于 2019-12-20 03:52:21
问题 Qestion First : I need to regex to match 111 or 111. or 111.111 (just aritrarty numbers) for a DocumentFilter . I need the user to be able to input 111. with a decimal and nothing afterwards. Can't seem to get it right. All the Regexes I find all match just all decimal numbers i.e. 12343.5565 32.434 32 Like this regex ^[0-9]*(\\.)?[0-9]+$ Problem is, I need the regex for a DocumentFilter so the input can only be numbers with/without a decimal point. But the catch is it also needs to match