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.

1037 questions
8
votes
5 answers

Clickable text in a JTextPane

I have a JTextPane declared like the following: JTextPane box = new JTextPane(); JScrollPane scroll = new JScrollPane(); StyledDocument doc = box.getStyledDocument(); scroll.setViewportView(box); scroll = new JScrollPane(box); And I am appending…
Joe
  • 835
  • 2
  • 9
  • 20
8
votes
3 answers

setContentType("text/html") for JTextPane doesn't work as it is expected

When you setContentType("text/html") it is applied only for the text that is set via JTextPane.setText(). All other text, that is put to the JTextPane via styles is "immune" to content type. Here is what I mean: private final String[] messages =…
Dragon
  • 2,431
  • 11
  • 42
  • 68
7
votes
1 answer

Why is Document.insertString()'s runtime not constant-time?

I am working on creating a logger to show output as part of a larger Java swing GUI. Unfortunately I was experiencing a slowdown after adding it. I have traced the problem to repeated calls of Document.insertString(). I made a test which shows this…
code11
  • 1,986
  • 5
  • 29
  • 37
7
votes
2 answers

Coordinates of a JTextPane to make a Screenshot in Java

I hope some one can help me, this is what I want to do. I have a JTextPane and I want to take a screenshot to that specific JTextPane coordinates and size, so far I can do a screenshot with the size of the JTextPane but I can't get the specific…
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
5 answers

Changing color of selected text in jTextPane

I am creating a text editor using a JTextPane that allows the user to change the color of selected text. But when the user selects the text, then chooses the option to change the color (say, to red) the text does not appear as red until the text is…
smith8ar
  • 91
  • 1
  • 9
7
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
  • 21,894
  • 86
  • 261
  • 463
6
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
  • 5,297
  • 12
  • 50
  • 71
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,486
  • 2
  • 28
  • 47
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,924
  • 13
  • 46
  • 80
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
  • 98,895
  • 36
  • 105
  • 117
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
  • 17,902
  • 15
  • 33
  • 34
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
  • 567
  • 1
  • 9
  • 22
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
  • 801
  • 4
  • 12
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
1 2
3
69 70