How do I append text to a JTextPane?

I've only used JTextAreas in the past, but my current project needs colored text, so I need to use JTextPane or JEditorPane. From googling JTextPane seems simpler but I still cant understand how I actually add text
14 Replies
JavaBot
JavaBot10mo ago
This post has been reserved for your question.
Hey @blockgoblin31! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP10mo ago
but how would I use that to color specific parts of the text? wouldn't that color the whole thing then the text is set?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP10mo ago
Stack Overflow
How to change text color in the JTextArea?
I need to know how to do this: Let's say: I have a code in the JTextArea like this: LOAD R1, 1 DEC R1 STORE M, R1 ADD R4, R1,8 I wanted to change the color of LOAD, DEC, STORE and ADD to color B...
blockgoblin31
blockgoblin31OP10mo ago
I just cant figure out what that's doing to add more text and what you linked is using the same code pretty much
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
blockgoblin31
blockgoblin31OP10mo ago
ok, I think that makes sense how do I set the default side of the window? in columns and rows also it isn't working using this code
set = context.addAttribute(set, StyleConstants.Foreground, s.getColor());
int length = getDocument().getLength();
setCaretPosition(length);
setCharacterAttributes(set, false);
replaceSelection(String.valueOf(s.getText()));
set = context.addAttribute(set, StyleConstants.Foreground, s.getColor());
int length = getDocument().getLength();
setCaretPosition(length);
setCharacterAttributes(set, false);
replaceSelection(String.valueOf(s.getText()));
s is just a wrapper for a Color and a char set is an AttributeSet where im just changing out the color
blockgoblin31
blockgoblin31OP10mo ago
actually heres the full class
blockgoblin31
blockgoblin31OP10mo ago
and here's Symbol.java
blockgoblin31
blockgoblin31OP10mo ago
@imp_o_rt
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
blockgoblin31
blockgoblin31OP10mo ago
bump
JavaBot
JavaBot10mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server