jtextpane

How to prevent JScrollPane arrow key handling from moving caret when Scroll Pane wraps Text Pane

▼魔方 西西 提交于 2019-12-19 11:54:13
问题 I have the following requirements: I need a scrollable JTextPane. The user may type into this text pane, or text may be inserted into it that is not typed by the user. Think something like an IM window. Although the window must be scrollable to allow the user to review text previously typed, the caret should never move from its position at the end of the text. Any text entered by the user will always appear at the end. In JTextPane, when the user scrolls with the scroll bar, the caret does

JTextPane prevents scrolling in the parent JScrollPane

偶尔善良 提交于 2019-12-19 08:58:13
问题 I have the following "tree" of objects: JPanel JScrollPane JPanel JPanel JScrollPane JTextPane When using the mouse wheel to scroll over the outer JScrollPane I encounter one annoying problem. As soon as the mouse cursor touches the inner JScrollPane, it seems that the scrolling events get passed into that JScrollPane and are not processed anymore by the first one. That means that scrolling the "parent" JScrollPane stops. Is it possible to disable only the mouse wheel on the inner JScrollPane

How do I easily edit the style of the selected text in a JTextPane?

落爺英雄遲暮 提交于 2019-12-19 07:45:07
问题 How do I easily edit the style of the selected text in a JTextPane? There doesn't seem to be many resources on this. Even if you can direct me to a good resource on this, I'd greatly appreciate it. Also, how do I get the current style of the selected text? I tried styledDoc.getLogicalStyle(textPane.getSelectionStart()); but it doesn't seem to be working. 回答1: Take a look at the following code in this pastebin: http://pbin.oogly.co.uk/listings/viewlistingdetail/d6fe483a52c52aa951ca15762ed3d3

How do I easily edit the style of the selected text in a JTextPane?

纵然是瞬间 提交于 2019-12-19 07:44:06
问题 How do I easily edit the style of the selected text in a JTextPane? There doesn't seem to be many resources on this. Even if you can direct me to a good resource on this, I'd greatly appreciate it. Also, how do I get the current style of the selected text? I tried styledDoc.getLogicalStyle(textPane.getSelectionStart()); but it doesn't seem to be working. 回答1: Take a look at the following code in this pastebin: http://pbin.oogly.co.uk/listings/viewlistingdetail/d6fe483a52c52aa951ca15762ed3d3

How to implement bullet points in a JTextPane?

妖精的绣舞 提交于 2019-12-18 09:01:03
问题 I have a JTextPane with a StyledDocument and RTFEditorKit implemented. How can I add bullet points (preferrably multi-level ones) onto the JTextPane ? 回答1: Well it does not have built in support for this, however here is a great link with tutorial on creating bulleted and numbered lists in JTextPane and JEditorPane s: Bullets and Numberings in the JEditorPane/JTextPane. 回答2: Figured it out doing this: HTMLEditorKit.InsertHTMLTextAction bulletAction = new HTMLEditorKit.InsertHTMLTextAction(

How to modify letter-spacing in a JTextPane?

半城伤御伤魂 提交于 2019-12-18 08:57:10
问题 I'm need to modify letter-spacing (font tracking) in a JTextPane, and I can't get it to work. When I'm using a JTextArea, I can just do: Font font = new Font("Courier New", Font.PLAIN, 10); HashMap <TextAttribute, Object> attrs = new HashMap<TextAttribute, Object>(); attrs.put(TextAttribute.TRACKING, -0.1); font = font.deriveFont(attrs); textArea.setFont(font); but as I need to change line spacing, I need to use a JTextPane, and doing: textPane.setFont(font) as I did with the JTextArea doesn

Toggling text wrap in a JTextpane

微笑、不失礼 提交于 2019-12-18 07:05:14
问题 How would I go about toggling text wrap on a JTextpane ? public JFrame mainjFrame = new JFrame("Text Editor"); public JTextPane mainJTextPane = new JTextPane(); public JScrollPane mainJScrollPane = new JScrollPane(mainJTextPane); mainjFrame.add(mainJScrollPane); 回答1: See No Wrap Text Pane. Edit: Well, if you want to toggle the behaviour, then you would also need to toggle the getScrollableTracksViewportWidth() value. See Scrollable Panel. You should be able to toggle between FIT and STRETCH.

JTextPane highlighting issue

一个人想着一个人 提交于 2019-12-18 03:46:43
问题 The last days I have been trying to implement a highlighting feature in a small text editor. For some reason I get a strange result: The given example should highlight each "dolor" - the first occurences are correctly found and highlighted but the next ones aren't. Here is the code I wrote so far: import java.awt.Color; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing

Resize dialog message (JOptionPane) for long sentence with fixed width

喜欢而已 提交于 2019-12-18 03:43:54
问题 I'm trying to resize the height of the dialog box ( JOptionPane ) for long sentence with hyperlink. My code is .. public class DialogTest { public static void main(String[] args) throws Exception { JTextPane jtp = new JTextPane(); Document doc = jtp.getDocument(); for (int i = 0; i < 50; i++) { doc.insertString(doc.getLength(), " Hello Java World ", new SimpleAttributeSet()); if ((3 == i) || (7 == i) || (15 == i)) { doc.insertString(doc.getLength(), " Hello Java World ", new

Wrap long words in JTextPane (Java 7)

≯℡__Kan透↙ 提交于 2019-12-18 03:17:09
问题 In all versions of Java up to 6, the default behaviour of a JTextPane put inside a JScrollPane was: wrap lines at word boundaries if possible. If not, then wrap them anyway. In JDK 7, the default behaviour seems to be: wrap lines at word boundaries if possible. If not, just expand the width of the JTextPane (never wrap long words). It is easy to reproduce this, here is a SSCCE: public class WrappingTest extends JFrame { public static void main ( String[] args ) { new WrappingTest(); } public