Questions tagged [jtextarea]

A JTextArea is a multi-line area that displays plain text.

A JTextArea is a multi-line area that displays plain text.
It is intended to be a lightweight Java Swing component that provides source compatibility with the java.awt.TextArea class where it can reasonably do so.

2035 questions
15
votes
1 answer

Auto text scroll for text area (JTextArea) with caret position set to the beginning of the last line

I have a simple Java question here. I want to auto text scroll to the beginning of the last line of a text area created using JTextArea. The amount of text per line of the text area is quite longer than the width of the text area. Here is the code…
SSaikia_JtheRocker
  • 5,053
  • 1
  • 22
  • 41
14
votes
3 answers

How to add text to a textArea instead of replacing it

How can I add text to a JTextArea instead of replacing all of it? I know about setText(String) but other than that I'm a bit lost.
vamp658
  • 225
  • 2
  • 3
  • 9
13
votes
1 answer

Java - JPanel with margins and JTextArea inside

I want to create something like this: Main panel has its margins (x), and TextArea in the center of that panel which almost fills up the panel. At the bottom is another panel with custom size (height y), which can be toggled visible and unvisible…
Jan Kowalski
  • 233
  • 2
  • 3
  • 7
13
votes
5 answers

JScrollPane scrolling with arrow keys

I've a JTextArea component inside JScrollPane and the text area is not editable. I would like to enable scrolling of the text area with up and down arrow keys (i.e. pressing the arrow keys will scroll the text area by one line). Any ideas how to…
JooMing
  • 922
  • 2
  • 7
  • 14
13
votes
4 answers

How can I create a JTextArea with a specified width and the smallest possible height required to display all the text?

In all the examples that I can find that use a JTextArea, the height & width is known before constructing the JTextArea, and if the JTextArea would require more height, then it is put inside of a JScrollPane. Obviously, the height of JTextArea is…
Nate W.
  • 9,141
  • 6
  • 43
  • 65
13
votes
2 answers

Java JTextArea that auto-resizes and scrolls

I have a JTextArea in a JPanel. How can I have the JTextArea fill the whole JPanel and resize when the JPanel resizes and scroll when too much text is typed in?
None
  • 3,875
  • 7
  • 43
  • 67
13
votes
2 answers

Getting JTextArea to display fixed-width font without antialiasing

Does anybody know how to get JTextArea to display a fixed size font on all platforms? I want to make a simple code editor with save/open functionality, which is simple enough, but I would like to get font to be fixed-size, preferably courier…
Dmytro
  • 5,068
  • 4
  • 39
  • 50
12
votes
4 answers

How to set the orientation of JTextArea from right to left (inside JOptionPane)

I have JScrollPane with JTextArea inside it and I am trying to set the JTextArea's orientation from right to left so the text inside it will start from the right and the scrollbar will be on the left I've tried the following but they didn't affect…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
12
votes
7 answers

How to calculate the number of rows (and columns in each row) a text takes in a JTextArea?

After getting interested in the problem presented in the question I tried to approach it few times and failed, and I do not like that :) I think if the problem was split into sub issues it might help to solve it. For simplicity lets assume the…
Boro
  • 7,913
  • 4
  • 43
  • 85
12
votes
3 answers

Java / Swing : JTextArea in a JScrollPane, how to prevent auto-scroll?

here's a runnable piece of code that shows what my "problem" is. I've got a JTextArea wrapped in a JScrollPane. When I change the text of the JTextArea, the JScrollPane scrolls automatically to the end of the text and I don't want that. Here are my…
SyntaxT3rr0r
  • 27,745
  • 21
  • 87
  • 120
12
votes
4 answers

How to set output stream to TextArea

I'm trying to create a GUI Panel for a program and I'd like everything, that would normally print to my command prompt, to print to a TextArea object. I have the GUI panel formatted for the most part, I can't get the text to print to the TextArea…
Dan
  • 649
  • 4
  • 11
  • 19
12
votes
4 answers

How to change highlighting color in Java Swing TextArea? And also, change the beginning of text corresponding to the highlighting location

Problem 1: BY using defaulthighlighter, I can make the focused lines change to blue. Now I want to change it to other colors. Do anyone know how to change this parameter? --- solved Problem 2: pos is the beginning index of my substring which I want…
AnneS
  • 1,493
  • 3
  • 14
  • 19
11
votes
3 answers

how to visualize console java in JFrame/JPanel

I made a Java program using Swing libraries. Now I would like to redirect my console outputs into a JFrame or JPanel.
Gianfra
  • 1,119
  • 4
  • 17
  • 33
11
votes
3 answers

How to count the number of lines in a JTextArea, including those caused by wrapping?

I have a JTextArea for which I have set word-wrap and wrap-style-word to true. I want to "pack" the JTextArea to the minimum possible height given a specified width. To do this, I'm planning calculating the height of the font using... Font font =…
peskal
  • 1,213
  • 1
  • 12
  • 28
11
votes
3 answers

Java: column number and line number of cursor's current position

I want to know the column number and row number where the cursor in JTextArea. ie. in notepad when i m at first line than status bar shows Ln 1, Col 1. thanks in advance...
Harry
  • 137
  • 2
  • 2
  • 11