jtextpane

How to implement an auto-complete for a text editor written in java?

空扰寡人 提交于 2019-12-04 17:32:32
I'm trying to create a text editor like program for coding in mips assembly using java , the point i got mixed up alittle was the part i was trying to provide a Control-Space feature like that of eclipse's.For example when the user enters add $s1 , then presses ctrl+Space , i would replace this string: "add $s1 , $s2 , $s3" with what he has typed! ( that's an example .. i know add can be of immediate type instructions :D ), I'm using a hashmap to bind key strokes to what will actually happen in my JTextPane , sth like : InputMap inputMap = textPane.getInputMap(); KeyStroke key = KeyStroke

How can I create an AutoComplete popup in a JTextPane in Java?

半世苍凉 提交于 2019-12-04 14:52:10
I am creating a SQL editor. I am using JTextPane for the editor. I want to implement AutoCompletion for table name etc. like Eclipse. I think the appropriate class for displaying info on top of another component is JPopupMenu , which already handles layering correctly to display itself. JPopupMenu has a show() method that takes its 'parent' component as an argument, and it will show itself in that component's coordinate space. Since you want to display a selection of terms for the user to choose from, a menu seems appropriate. To check for text changes, you'd add a DocumentListener to the

Increasing the font size of a JTextPane that displays HTML text

一个人想着一个人 提交于 2019-12-04 14:03:47
Lets say that I have a JTextPane that is showing a HTML document. I want that, on the press of a button, the font size of the document is increased. Unfortunately this is not as easy as it seems... I found a way to change the font size of the whole document, but that means that all the text is set to the font size that I specify . What I want is that the font size is increased in a proportional scale to what was already in the document. Do I have to iterate over every element on the document, get the font size, calculate a new size and set it back? How can I do such an operation? What is the

Enabling word wrap in a JTextPane with HTMLDocument

可紊 提交于 2019-12-04 07:46:17
Everywhere I read answers of people finding ways of enabling word wrapping in a JTextPane , but none of them work for me. I'm using an HTMLDocument (to display "text/html" content) and nothing that I have found so far got it to work. The JTextPane always cause the JScrollPane to scroll horizontally. I need the JTextPane to be scrollable, but only vertically. Would anyone have a workable demo of a word wrapping JTextPane displaying HTML content? Use this as example to implement custom wrap (whatever you need) http://java-sl.com/tip_html_letter_wrap.html http://java-sl.com/wrap.html There are

Adding a JTextPane to BorderLayout.SOUTH causes JScrollPane to scroll

最后都变了- 提交于 2019-12-04 06:00:56
问题 I have a JPanel which is contained within a JScrollPane. The JPanel has components added to it's NORTH, CENTER, WEST and SOUTH areas (BorderLayout). When I add a JTextPane to the SOUTH position, the scroll pane scrolls to show the text. I do not want the scroll pane to move from its topmost position. How can I prevent this? 回答1: Absent more details, you can try setting the default caret to NEVER_UPDATE, available since Java 5. JTextPane jtp = new JTextPane(); DefaultCaret caret =

Changing the mouse pointer in JtextPane

别说谁变了你拦得住时间么 提交于 2019-12-04 04:35:13
问题 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 回答1: You could try this: pane.setCursor(new Cursor(Cursor.HAND_CURSOR)); Where pane is your JTextPane . 回答2: Did you read my

Getting 'Attempt to mutate notification' exception

橙三吉。 提交于 2019-12-04 02:56:48
问题 My goal is to implement blue coloring of keywords written by user into JTextPane. This is how my code look like: private class DocumentHandler implements DocumentListener { @Override public void changedUpdate(DocumentEvent ev) { } @Override public void insertUpdate(DocumentEvent ev) { highlight(); } @Override public void removeUpdate(DocumentEvent ev) { highlight(); } private void highlight() { String code = codePane.getText(); SimpleAttributeSet defSet = new SimpleAttributeSet();

highlighting the word in java

两盒软妹~` 提交于 2019-12-04 02:19:59
问题 I am triying to highlight a word, but only .length()-2 at 1st time,delay and then last 2 words.The first words are highlighted but it is not highlighting the last two words after delay.please help. here is the code: import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame;

Highlight current row in JTextPane

情到浓时终转凉″ 提交于 2019-12-03 12:22:22
I'm trying for more than 2 days to implement a specific requirement for a text editor window... unfortunately without success so far :( The goal is to get a text editor window which will highlight the current row, like other text editors do. With current row I mean the row where currently the cursor/caret is positioned. I already found two different approaches but unfortunately I'm not able to adopt them so they work as expected. The first approach is to overwrite the DefaultHighlighter ( http://snippets.dzone.com/posts/show/6688 ). In the second approach the HighlighterPainter will be

JTextPane append HTML string

99封情书 提交于 2019-12-02 14:06:55
问题 I can parse the content of a JTextPane witout any problems in HTML: textPane = new JTextPane(); textPane.setContentType("text/html"); textPane.setText(<b>Hello!</b>); // ... setVisible(true); this results in Hello! But whenever I try to append a String to textPane, using styledDoc = (StyledDocument) textPane.getStyledDocument(); styledDoc.insertString(styledDoc .getLength(), <b>Goodbye!</b>, null ); (as seen in this question), my output is Hello! <b>Goodbye!</b> (without whitespaces) - so the