Questions tagged [documentfilter]

DocumentFilter is a Java Swing class that allows filtering of modifications to Document objects.

DocumentFilter is a Java Swing class that can be extended to provide filtering of modifications to Document objects made through insertions, removals and replacements.

105 questions
5
votes
2 answers

JTextField, using Document Filter to filter integers and periods

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…
Joao Bastos
  • 53
  • 1
  • 1
  • 4
5
votes
1 answer

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

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?
Aviv Cohn
  • 11,431
  • 20
  • 52
  • 95
5
votes
1 answer

using DocumentFilter.replace with unicode characters

I am building a GUI where one textfield must be typed in latin characters, the others in arabic. To avoid switching the keyboard layout, I choosed to maintain it in arabic and use a DocumentFilter in that particular textfield to replace arabic…
Brahim Gaabab
  • 190
  • 1
  • 7
5
votes
1 answer

How to make textfield have 2 document filters

I have a code here that i got form MDP's weblog. the sizefilter and the number filter. how do i make a textfield set its filter for two document filters. Here isthe numberfilter import javax.swing.text.BadLocationException; import…
Red Dunham
  • 51
  • 2
5
votes
7 answers

JTextField limiting character amount input and accepting numeric only

here's the code that i have on how to limit the character input length class JTextFieldLimit extends PlainDocument { private int limit; // optional uppercase conversion private boolean toUppercase = false; JTextFieldLimit(int limit) { …
Weddy
  • 513
  • 6
  • 10
  • 21
4
votes
1 answer

Why does the DocumentFilter not give the intended result?

I figure this must be a simple mistake in the code or a misunderstanding on my part, but I cannot get a DocumentFilter to detect insertString events. Below is a simple filter for upper case letters, but that is not as important as the fact that the…
Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405
4
votes
1 answer

DocumentFilter allowing only numbers and period (.) into JTextField?

\Here is the creation of the JTextField: hourlyWageInput = new JTextField("7.25"); DocumentFilter filter = new UppercaseDocumentFilter(); ((AbstractDocument)…
David Tunnell
  • 6,268
  • 17
  • 52
  • 109
3
votes
2 answers

JTextArea only with numbers, but allowing negative values

I have a JTextArea which only has to accept numbers. This is my code: DocumentFilter onlyNumberFilter = new AxisJTextFilter(); final JTextArea areaTextoXMin = new JTextArea(String.valueOf(xMin)); …
Roman Rdgz
  • 11,378
  • 36
  • 110
  • 192
3
votes
1 answer

How to use MaskFormatter and DocumentFilter together

I need to have a JFormattedTextField that allows only the input of ##-###** where the hyphen is always present in the text field and the last 2 characters, represented by the *, can either be 2 letters of the alphabet (a-z/ A-Z) or nothing at all. I…
exit_1
  • 1,100
  • 4
  • 11
  • 30
3
votes
1 answer

Document Filter vs. KeyListener vs. MaskFormatter

Before you jump all over me, please remember that each of you started out at some point (only saying that because I have seen the responses). Yes, I am learning, but need some help with the differences between DocumentFilter, KeyListener, or any…
cokeefe28
  • 75
  • 4
3
votes
3 answers

java change the document in DocumentListener

I use a DocumentListener to handle any change in a JTextPane document. while the user types i want to delete the contents of JTextPane and insert a customized text instead. it is not possible to change the document in the DocumentListener,instead a…
Soheil
  • 1,610
  • 6
  • 31
  • 63
3
votes
1 answer

How to exit from Java Swing application, avoiding messages generated from setInputVerifier

I have a text field where I have imposed some constraint in input data, by the help of InputVerifier. The constraint is if the text field is left empty, then an error message will pop up. When the application starts, the cursor remains on the text…
singha
  • 2,621
  • 3
  • 11
  • 4
3
votes
1 answer

How to insert text into a Document without triggering insertUpdate()

I want to create a Swing JTextPane that takes action when the user types text into it. But I also want to be able to alter the text in that pane without it treating that alteration as a user typing. How can I do this?
3
votes
0 answers

Time-inputfield for quick entering

I want a quick-to-use way for entering times down to centiseconds. Entering digits should push them in from the right and automatically add leading zeros, "." and ":" as needed, so for example: "" => "0.03" => "0.31" => "3.14" => "31.41" =>…
Stefan Pochmann
  • 24,379
  • 7
  • 36
  • 92
2
votes
2 answers

Using DocumentFilter.FilterBypass

I want to have a method like this on my DocumentFilter public void replaceUpdate(int offset, int length, String text) { try { super.replace(byPass, offset, length, text, null); } catch (BadLocationException ex) { …
Giannis
  • 4,687
  • 12
  • 50
  • 102
1
2 3 4 5 6 7