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;}");
Related
I am currently modifying the behavior of a JTable. My final goal is to allow selection of text in a cell, without making the cell editable through the use of the mouse right click. Everything should remain the same on hover, or when using the left click.
I am having trouble however when trying to do this. I have messed with non-editable text fields as cell editors, carets, and etc. but I can't seem to achieve the result I want.
Some resources I looked at include:
http://www.coderanch.com/t/332800/GUI/java/JTable-highlight-text-cell
Highlighting the text of a jtable cell
How to make a cell behave like it's editable but have it read only?
etc.
None of them have helped in my current predicament.
I have an Eclipse RCP application that has a widget that uses the rich text editor from org.eclipse.epf.richtext.RichTextEditor. So all the code is open to me to alter to how I see fit. I have found that the rte uses a browser to display the text.
My problem is that I want the rte to wrap the text and not put a horizontal scroll bar. So I was hoping to see if anyone has used this rte and figured out how to do this.
I think that in every SWT widget's constructor you can pass a style. So for example if you want vertical scroll but no horizontal you can do this:
new MyWidget(parent, SWT.V_SCROLL);
This way the widget won't scroll horizontally. the RichTextEditor itself does not have anything about text wrapping in its API so I guess that you can't alter that directly.
A little more about SWT styles: SWT style bits
Examine the HTML which is displayed in the SWT browser widget (call getText()). That should give you an idea how it's organized. Find the HTML element which wraps the editor, set it's width to 100% and make sure you do the same for the body and html elements to have the widget's width propagate to the editor element.
That should already fix the issue unless the text in the editor contains elements which are wider than the widget.
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'd like to change the color of the java titlebar and add some text to the ends and the middle.
The previous coder used setUndecorated(false) and a JPanel to achieve this effect but I am trying to change this to modify the actual title bar because the panel solution is an issue with menus and focus.
tl;dr Want to change the color of the titlebar and set text in the middle and one the ends.
I think you can change the title bar color with the method described here: http://www.coderanch.com/t/346141/GUI/java/set-JFrame-titlebar-color
Changing the text should be possible via setTitle(). You can call this method as many times as you want throughout the life of the application to change the title text on the fly.
I want to set every other line in a java text area to a second color, is there a way to do this?
example:
<red>1</red>
<blue>2</blue>
<red>3</red>
<blue>4</blue>
the red and blue tags are just for example only.
Neither java.awt.TextArea nor javax.swing.JTextArea support text (or background) decorations. It is one font & one style.
As indicated by Chris, a JTextPane (or JEditorPane) is designed for 'styled text' documents. JEP for example, will handle RTF & (simple) HTML/CSS formatting.