I have a JTextPane which has the content type text/plain. I set some texts to that JTextPane and it contain some texts which display URLs. I want to change the mouse pointer when I point the mouse to that text only into the hand pointer.
Is this function achievable?
Note: I have the content of the JTextPane as text/plain. It cannot be changed to text/html
thanx
You could try this:
pane.setCursor(new Cursor(Cursor.HAND_CURSOR));
Where pane is your JTextPane.
Did you read my answer in your posting on Adding tooltips to JTextPane?
Well the concept is the same. You use a MouseListener and convert the mouse point to get the text at the caret position. When you are over a url text then you change the cursor.
The Utilities class might help you access the text at the caret location.
If you need more help then post your SSCCE that shows what you have tried and shows what problems you are having.
Related
I want to highlight different sections of text when mouse is hovered over them. I'm currently using styleddocument with jTextPane. Can somebody please help me in defining style so that individual strings/paragraphs can be highlighted when mouseover occurs?
Thanks,
You can define a custom highlighter to show necessary colors. Add a MouseListener to the jTextPane. You can get mouse coordinates and use viewToModel() method of jTextPane to detect offset in the Document and process whether current section should be highlighted or not.
Without resorting to wrapping a GWT TextArea in a separate DIV, how to add a search icon/magnifier icon inside the text area?
No, Not possible.Text area is not a normal Widget.
GWT's TextArea maps directly to a HTML TextArea thats why you can only set text to it. The only thing you can do ist create a Grid/VerticalPanel/HorizontalPanel and put in each cell a separate TextArea.
Google Groups
Similar Question
Use a Composite wrapping a FlowPanel, put a text area and an image inside, then in CSS position the icon absolutely so it's over the text field.
I'm currently developing JTextArea with a Notepad++ like function (currently indentation function finished).
Now I'm trying to add a function which in my JTextArea will show a dotted line for an indentation with same level, and change specific color of a word.
Thanks in advance :)
You will not able to achieve your target with JTextArea as it is a plain text support component.You have to use a Styled text supported JEditorPane or JTextPane.And try to use a HTML document and achieve it.Look at
Styled supported components
and
some more examples
I have a JScrollPane that holds a JLabel using the following code:
//Create TEXT LOG JPanel
textLogPane = new JScrollPane(logLabel);
textLogPane.setPreferredSize(textLogPaneDim);
//textLogPane.setOpaque(true);
textLogPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));
textLogPane.getViewport().setBackground(Color.DARK_GRAY);
The JLabel, logLabel, is represented by a string with an HTML encoding using for carriage returns. I display certain images based on the contents of certain lines and I would like to be able to scroll the JScrollPane, textLogPane, to show that line whenever I am displaying that graphic. I know the contents of the line that I want to display but I can't seem to figure out how to get it to scroll down(or up) to the relevant line.
If need be I can change to something other than a JLabel as long as I can keep the HTML encoding and have it look just like multiple lines of text.
Sorry if this is a repeat I tried searching but couldn't find any results.
Thanks
You can do some custom maths and use scrollRectToVisible() in your viewport. I don't know how to compute the rect of a specific line in your JLabel. A better solution would be to stick your strings into a JList instead, perhaps with a custom renderer for the html, and use
list.ensureIndexIsVisible(list.getSelectedIndex());
You don't use "carriage returns" in HTML, you use "br" tags.
I would suggest you should probably be using a JTextPane for multiline text. I also find it easier to not use HTML, but instead to add strings with attributes. You can also insert icons into a JTextPane.
Read the section from the Swing tutorial on Using Text Components for a working example.
I have JTextPane on my window and i have JTextField. When i press enter enter in JTextField, the text gets added in JTextPane. Everything works fine and scrollbar too appears on its own. But, it doesn't appear properly. It automatically scrolls to the beginning of the content in JTextPane. How do i keep the scrollbar to the end of JTextPane?
The provided link in the accepted answer is an old link. You may want to check out Text Area Scrolling for additional information. The entry is for a text area but I believe the information applies to a text pane as well.
You can try by invoking
scrollPane.scrollRectToVisible(new Rectangle(0,main.getBounds(null).height,1,1));
This should be the most working approach. Otherwise try to search out scrollPane.setValue(..) or work with the caret: editorPane.setCaretPosition(...)
I found a discussion of the same problem. Have a look at http://www.coderanch.com/t/329964/GUI/java/JScrollpane-Force-autoscroll-bottom