jtextpane

Deselect selected text in JTextPane

拟墨画扇 提交于 2021-02-20 11:23:44
问题 I have an editor in which I want to check that selected text will not contain some words. If it contains those particular words, then I need to deselect the selection made by user. Is there any way to do that in JTextPane ? 回答1: Text selection is temporaray and contiguous. You can't unselect some text in the middle of a larger string of selected text. Maybe you are talking about highlighting. Check out the API for getHighlighter(). You can add/remove highlights and specify the start/end

reassign a new “character” to a key, so that it gets printed instead of the default letter for the key

此生再无相见时 提交于 2021-02-10 14:33:43
问题 I'm in the process of developing a text editor that has a "macro system," where the user can reassign values to the keys on their keyboard -- so that when they press the letter a, it might print the letter "z" instead. (Really, it'll be used for math symbols, not other letters). Can anyone get me started on the Java code to reassign a value to a key within a JTextPane? If you need more details, let me know. Thank you! So far, this is what I have: public void keyPressed(KeyEvent evt) { /

How do I set different colors for text and underline in JTextPane?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 14:16:58
问题 Just been trying to color the text in JTextPane - but the issue is cannot have different colors for text and the underline. How should I do that or is that even possible? The example below prints all the text and underline in RED. JTextPane pane = new JTextPane(); StyleContext context = new StyleContext(); Style style = pane.addStyle("Black", null); StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4);

How to scroll the contents to bottom by default in JTextPane?

时间秒杀一切 提交于 2020-02-24 08:44:39
问题 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? 回答1: I found a discussion of the same problem. Have a look at http://www.coderanch.com/t/329964/GUI/java/JScrollpane-Force-autoscroll-bottom 回答2: The

How to scroll the contents to bottom by default in JTextPane?

回眸只為那壹抹淺笑 提交于 2020-02-24 08:42:49
问题 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? 回答1: I found a discussion of the same problem. Have a look at http://www.coderanch.com/t/329964/GUI/java/JScrollpane-Force-autoscroll-bottom 回答2: The

Inserting Images into a JTextPane Error

故事扮演 提交于 2020-01-24 20:45:11
问题 I asked about this before, but, I decided to start a new thread with a SCCE, it compiles sucessfully but it doesn't insert the image. Can anyone troubleshoot as to why it does this? Thanks, Chris. Here is the full code: package mathnotesplus; import java.awt.Dimension; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.SwingUtilities; import javax.swing.JPanel; import javax.swing.JTextPane; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree

Can't remove extra line spacing in JTextPane for html content

混江龙づ霸主 提交于 2020-01-21 21:52:32
问题 I can't squeeze together the lines in a Java JTextPane if I set the content-type to text/html . I would like them as close together as they are when the content-type is text/plain , the default. The line-height , top-margin , ... CSS properties don't seem to help :(. This is the output of my sample program, that shows that the lines do take more space when a HTML editor handles the rendering: alt text http://lh6.ggpht.com/_Wx4sMDdKKdU/S8cYWIPKhzI/AAAAAAAAAig/4QzFwygmEBs/simpleTextPane.PNG The

Get a component from a JTextPane through javax.swing.text.Element?

点点圈 提交于 2020-01-19 16:22:50
问题 I am using a JTextPane to display characters and symbols, where the latter are represented by custom painted JComponents . For example, the text pane might show something like this: The text pane is user editable and it is allowed for the user to add more symbols via a button at any position and as a replacement for selected text. I do this via the JTextPane.insertComponent() method. At some point in the application I need to know what is currently being displayed in the text pane, and by