JTextComponent is the base class for swing text components. It tries to be compatible with the java.awt.TextComponent class where it can reasonably do so. Also provided are other services for additional flexibility (beyond the pluggable UI and bean support).
Questions tagged [jtextcomponent]
149 questions
6
votes
2 answers
Java text based application
The main idea is to try and make an application that would have look-and-feel of a standard Linux-type terminal. Now I am limited to Java and here is what I want.
Main Window (independent JFrame) with top menu (ok this I know how to do)
Entire area…

Fedja Blagojevic
- 813
- 1
- 10
- 18
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
- 15,543
- 25
- 68
- 131
5
votes
2 answers
How to use TextAction
What are the purposes of using TextAction from AbstractAction? and how to use it for the following:
Caret
Selection in the JTextComponents
KeyBindings

mKorbel
- 109,525
- 20
- 134
- 319
4
votes
1 answer
JTextPane preferred size with fixed width
I have a question on how I could easily compute the preferred size/height of a JTextPane given a fixed width. What I have done so far is put my JTextPane in a JScrollPane and whenever I update the text, I update the size of the JScrollPane. Now,…

Guillaume Polet
- 47,259
- 4
- 83
- 117
4
votes
3 answers
Getting the removed text from a Java text component
A JTextComponent allows you to add a DocumentListener to its Document, which will tell you when text was added or removed, and the offset and length of the change. It will not, however, tell you what the text of the change was.
This is not much of…

Amanda S
- 3,266
- 4
- 33
- 45
4
votes
2 answers
JScrollBar Vertical/Horizontal setting problem- Java Swing
I am just trying to add a vertical scroll bar to my TextField and TextArea.
I am using a ScrollPane and it should create avertical/horizontal scroll bar by default.
Problem:
I need a vertical scroll bar to see the data which is not visible.
In the…

JJunior
- 2,831
- 16
- 56
- 66
4
votes
4 answers
Updating the sum of jTextFields automatically everytime they change (Java)
as part of my java learning I made a jForm using netbeans which contains three jTextFields for the user to enter some numbers and then the sum of those numbres is displayed in another jTextField. This is, of course, extremely easy, but I want to be…

Alex Terreaux
- 1,881
- 5
- 23
- 39
3
votes
3 answers
WYSIWYG XML Editor java
I need to write a swing based editor that can open specified xml files, which contains the text i have to use between a
and
tag, but there are other tags in the file too. There are other useless informations in the file.I don't need to…
Halufolia
- 61
- 2
- 8
3
votes
2 answers
Deactivate ScrollOnExpand on JScrollPane
I want to prevent the scrollpane from scrolling when the content in its view expands. Any pointers? I've tried Googling variations on the title, as well as reading all the docs for JScrollPane, and I'm still a bit baffled.
Edit:
Within the scroll…

kazoo
- 137
- 2
- 7
3
votes
1 answer
Overwriting getText of JTextField
I wish to overwrite getText() so that it can return a null value instead of a a blank value. I noticed that getText() is a part of JTextComponent and I've been unable to successfully overwrite it. What is the best way to get the desired result?

Patrick
- 351
- 1
- 4
- 15
3
votes
0 answers
ASCII Non printable characters in textcomponent
My situation is that i have to scan a qrcode in a textfield that i have to parse that comes with non-printables characters (btw it's always the same character) that never comes in the same position.
I try to get this code with no success…

nachokk
- 14,363
- 4
- 24
- 53
3
votes
2 answers
How do I make the caret of a JTextComponent skip selected text?
the normal behaviour of native text fields in many environments is as follows:
Textfield with text "abcdefg". I use the mouse to select "efg" from left to right. The caret is now behind "g". When I move the caret to the left by pressing the cursor…

user1573546
- 523
- 5
- 13
3
votes
3 answers
Polish letters from JTextField
How to get String from JTextField or JTextArea with Polish letters?
when I use myTxtArea.getText() and in my JTextArea I've got ĄĆĘŁŃÓŚŹŻąćęłńóśźż it only recognizes ?????Ó????????ó???.
Text from both JTextField and JTextArea is going to be saved in…

knowbody
- 8,106
- 6
- 45
- 70
3
votes
4 answers
How to get the added, removed or changed chars from DocumentListener?
I have JTextAreas and need to get chars, which are added, removed or changed to it. How do I do this?
c0d3x
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,676
- 7
- 34
- 65