Questions tagged [jtextpane]

A Java Swing text component that can be marked up with attributes that are represented graphically.

A Java Swing text component that can be marked up with attributes that are represented graphically. You can find how-to information and examples of using text panes in Using Text Components, a section in The Java Tutorial.

1014 questions
7
votes
2 answers

Limit JTextPane memory usage

I have an application which continuously receives data on a socket, and then logs this data to a file while also displaying this data in a JTextPane. Naturally, as data is written to the underlying document of the JTextPane the memory usage…
tjansson
  • 324
  • 2
  • 11
7
votes
1 answer

Inserting some characters in JTextPane causes performance problems and memory leak

My chat client has a JTextPane in which text is inserted, which can be up to a few lines per second. It usually works fine, even for a longer period of time (e.g. an hour), however sometimes it just gets incredibly slow, using a lot of CPU and…
user2375667
  • 273
  • 2
  • 10
7
votes
4 answers

How to get the number of lines from a jtextpane

Is there a way of "extracting" the number of lines from a filled with text jtextpane? If there is, does it work if some of the lines are due to text wrapping?
martin
  • 917
  • 2
  • 14
  • 31
6
votes
1 answer

Java Print API - Space character incorrectly printed using monospaced 'Courier New' font

Let me first describe the picture below: There are two printed papers. The only difference between them is that few space " " characters from paper in left are replaced by dot "." character in the paper in right. Red line represents the left border…
Michal Vician
  • 2,296
  • 2
  • 21
  • 46
6
votes
1 answer

JTextPane clear text

I'm trying to remove all text from a JTextPane. I thought you could simply use: textPane.setText(""); This DOES work, but for some reason, there always is an empty line after calling that method. Why is that and how do I prevent that?
Bv202
  • 3,624
  • 11
  • 41
  • 76
6
votes
5 answers

How do I easily edit the style of the selected text in a JTextPane?

How do I easily edit the style of the selected text in a JTextPane? There doesn't seem to be many resources on this. Even if you can direct me to a good resource on this, I'd greatly appreciate it. Also, how do I get the current style of the…
Evan Fosmark
  • 89,147
  • 33
  • 99
  • 116
6
votes
1 answer

How is word-wrapping implemented in JTextPane, and how do I make it wrap a string without spaces?

How exactly is word-wrapping implemented in JTextPane? I'm trying to understand exactly how it works so that I can modify the behavior. Right now, if I have a standard JTextPane inside a JScrollPane, it will break text at spaces, but not inside long…
A Coder
  • 455
  • 1
  • 6
  • 16
6
votes
4 answers

Adding text to a JTextPane without having it editable by the user?

So I've created my own text pane class (extending JTextPane) and I'm using the method below to add text to it. However, the pane needs to be editable for it to add the text, but this allows a user to edit what is in the pane as well. Can anyone tell…
Fran Fitzpatrick
  • 16,032
  • 15
  • 31
  • 33
6
votes
5 answers

Which is the right regular expression to use for Numbers and Strings?

I am trying to create simple IDE and coloring my JTextPane based on Strings (" ") Comments (// and /* */) Keywords (public, int ...) Numbers (integers like 69 and floats like 1.5) The way i color my source code is by overwritting the insertString…
user3188291
  • 527
  • 1
  • 6
  • 21
6
votes
1 answer

Swing text API: Override LabelView with different string length?

I've got a StyledDocument instance that contains, among other things, strings that represent numbers. By overriding the attributes of the string's element, I'm using a custom View for them that I derived from LabelView. I want to allow the user to…
fpw
  • 781
  • 3
  • 12
6
votes
1 answer

Syntax-Highlighting in JTextPane using SwingWorker

I am trying to do text highlighting in JTextPane. I'm using SwingWorker to do highlighting in background. But i'm unable to get desired output. My Code is as Follow: Main Class: class MultiColor { private static void displayGUI() { final…
Sachin Kumar
  • 731
  • 1
  • 9
  • 24
6
votes
2 answers

Search text file and display results in a JPanel

Does anyone have any ideas on how I can search a text file and list the results in a JComponent, like a JPanel. I've been trying to make this work out for two days now, but no success will really appreciate a reply. Thanks a lot in advance. I've…
Oliver Muchai
  • 279
  • 1
  • 8
  • 18
6
votes
1 answer

JTextPane text background color does not work

I am trying to make a small HTML-wysiwyg with a JTextPane but I can't get the BackgroundAction to work. I am using setCharacterAttributes on the StyledDocument of the JTextPane but it seems problematic. The view is ok but the Document is not. Here…
Guillaume Polet
  • 45,783
  • 4
  • 79
  • 115
6
votes
2 answers

JTextPane: How to set the font size

Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.util.ArrayList; import java.util.Scanner; import javax.swing.*; import…
PeakGen
  • 18,056
  • 71
  • 208
  • 385
5
votes
2 answers

setting JTextPane to content type HTML and using string builders

I'm using string builders to append text to my JTextPane, I've set content type as pane.setContentType("text/html"); but the no text actually appears on my JTextPane. This is an example of my append: buildSomething.append("
orange
  • 4,808
  • 12
  • 44
  • 68
1 2
3
67 68