Is there any way to put HTML into my SWT TreeViewer? I want my LabelProvider getText() String to be interpreted as HTML code.
No, the TreeViewer does not support HTML.
You can do things like bold or italic text by using a label provider based on StyledCellLabelProvider.
Related
I want to build a chat room whit java swing.
I want to have a component to show text, image, gif and emoji.
please help me to select a good component.
In first I choose JtextPane for this.Is it good?
In first I choose JtextPane for this.Is it good?
Yes, I would use a JTextPane, with normal text (not HTML). With a JTextPane you can:
text with attributes.
align text to the right/left of the text pane
display icons using the insertIcon(...) method.
Read the section from the Swing tutorial on Text Component Features for some examples that use attributes when adding text.
I was wondering if there is a way to append an error message in a jTextArea with different font color.
Like this it will make a difference between the normal output that I am appending and the error output.
For example, on Netbeans the system.err font color is red, and the System.out is appearing black.
JTextArea only allows a single color to be used. You can use a JTextPane instead
Two Swing classes support styled text: JEditorPane and its subclass JTextPane. The JEditorPane class is the foundation for Swing's styled text components and provides a mechanism through which you can add support for custom text formats.
If you want unstyled text, use a text area instead.
Source :Styling Dynamically
I afraid it is not possible to display colored text in jtextarea. you can only do that on jtextpane and here how .
I'm writing a Text comparing tool and would like to show the charaters who are not same in Red.
Thatfor I have to change the Color (with setForeground()?) of a Passage of the Text.
How can I do that?
You can use "< html>Some text< font color...>some text< /font>< /html>" for the cell's text.
Instead of labels you will need to use a JEditorPane as your rendering component.
Look here for inspiration:
How to insert JEditorPane into JTable cell?
I have a JTextPane with HTML contents. Without changing the content type or calling setText, I would like disable the hyperlinks. I want
The hyperlinks to have the same style as the surrounding text (usually meaning no underline or blue color)
The mouse to not turn into a hand when I move it over hyperlinks
What is the easiest way to do this? I already know how to change the hyperlink listener, but now want the links to appear as normal text.
You can define desired style for your "a" tag.
E.g. to set forn bigger use
((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule("a {font-size:48px;}");
Can I alter the text of a JTextArea to bold (append text) and then back to normal and will it only display the bold text in bold and the rest as normal?
Also can the contents of JTextArea be saved as an RTF document?
No. What you're looking for is JEditorPane
This supports HTML (3.2?) which will allow you to use <font> (and other older tags) to provide rich text.
JEditorPane textarea = new JEditorPane("text/html", "");
textarea.setText("Here is some <b>bold text</b>");
EDIT: According to the javadoc I referenced above, JEditorPane also supports limited RTF. Don't forget to change the MIME to text/rtf
textArea.setFont(textArea.getFont().deriveFont(Font.BOLD, textArea.getFont().getSize()));
I believe you need a JTextPane or JEditorPane for that.