jtextpane

JtextEditorPane - How to prevent copy and paste from wrapping text in html paragraph tags?

五迷三道 提交于 2019-12-08 03:16:36
问题 I have: HTMLDocument document = new HTMLDocument(); JTextPane htmlEditorPane = new JTextPane(document) htmlEditorPane.setContentType("text/html"); I then select some text in the middle of a sentence and call (wrapped in the appropriate ActionListeners): htmlEditorPane.copy(); htmlEditorPane.paste(); For whatever reason whenever I do this the text that is copy and pasted is wrapped in <p> tags. How can I keep all the formatting but the <p> tags that seem to be added? 回答1: Use

How to get selection from JTextPane

邮差的信 提交于 2019-12-08 01:20:10
问题 I want to find out which part of JTextPanel text is selected. Tried to call JTextPane.getSelectionStart() and JTextPane.getSelectionEnd() , but they always return same value that is equal to current caret position. What is my problem with that? I would be thankful for any code exapmle that gets current selection. 回答1: Have a look at JTextComponent#getSelectedText(). You'd simply call this method on the instance of your JTextPane and it will return the selected text of your JTextPane . Did a

Java JTextPane RTF Save

社会主义新天地 提交于 2019-12-07 18:44:55
问题 i have the following code trying to save the contents of a JTextPane as RTF. although a file is created in the following code but it is empty! any tips regarding what am i doing wrong? (as usual dont forget im a beginner!) if (option == JFileChooser.APPROVE_OPTION) { //////////////////////////////////////////////////////////////////////// //System.out.println(chooser.getSelectedFile().getName()); //System.out.println(chooser.getSelectedFile().getAbsoluteFile()); //////////////////////////////

Insert a picture into a JTextPane

末鹿安然 提交于 2019-12-07 18:17:50
问题 In my notepad application, I am trying to add an image as if it were a JLabel into a JTextPane by clicking on a JMenuItem called Picture . private class Picture implements ActionListener { public void actionPerformed(ActionEvent event) { fc = new JFileChooser(); FileNameExtensionFilter picture = new FileNameExtensionFilter("JPEG files (*.jpg)", "jpg"); fc.setFileFilter(picture); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); if (fc.showDialog(Notepad.this, "Insert")!

Method that returns the line number for a given JTextPane position?

纵然是瞬间 提交于 2019-12-07 15:37:04
问题 I'm looking for a method that computes the line number of a given text position in a JTextPane with wrapping enabled. Example: This a very very very very very very very very very very very very very very very very very very very very very very long line. This is another very very very very very very very very very very very very very very very very very very very very very very long line. | The cursor is on line number four, not two. Can someone provide me with the implementation of the

Java JTextPane HTML Editor UTF-8 characters encoding

浪子不回头ぞ 提交于 2019-12-07 15:27:19
问题 I'm using JTextPane as simple html editor. jtp=new JTextPane(); jtp.setContentType("text/html;charset=UTF-8"); jtp.setEditorKit(new HTMLEditorKit()); When I call jtp.getText() I get nice html code with all special chars escaped. But I don't want escape national characters (polish) but only special html chars like &, <, > When I enter in editor <foo>ą ś & I get <foo>ą ś & but I would like get <foo>ą ś & How it is possile? 回答1: That's not possible, unfortunately. There's a flaw inside javax

Change specific String attributes in StyledDocument

爷,独闯天下 提交于 2019-12-07 08:16:53
问题 I am trying to create a text editor. I am using a JTextPane with a StyledDocument. What I am trying to implement is a way to change the attributes of selected text. This works in the following way : the user inputs the desired text. Afterwards, he can change any String's attributes (Font family, font size, whether it is bold/italic or not) by selecting it and pressing a button, where by means of checkboxes and dropdown lists would select the desired changes. Is it possible for me to change

Java HTMLDocument (insertAfterEnd, insertAfterStart, insertBeforeEnd, insertBeforeStart) not working?

爷,独闯天下 提交于 2019-12-07 06:15:37
问题 I have a JEditorPane that displays HTML that is generated programmatically (at runtime). Up to now when I was adding a "line" I was re-creating the whole HTML text in a string buffer and then passing it to JEditorPane.setText method. Now the HTML created has become quite large (can reach up to a few MB) and I would simply add my new line at the end instead of re-generating all the HTML text. The reason I try to append at the end is to avoid Swing (or the kit ?) having to render/parse the

Limit JTextPane memory usage

强颜欢笑 提交于 2019-12-07 01:34:00
问题 I have an application which continuously receives data on a socket, and then logs this data to a file while also displaying this data in a JTextPane. Naturally, as data is written to the underlying document of the JTextPane the memory usage continues to increase. Is there a simple way of limiting the memory which the JTextPane is allowed use? I would like the JTextPane to work similar to how a typical command shell's command history works. 回答1: just check the content and wipe it accordingly

Monospaced font/symbols for JTextPane

删除回忆录丶 提交于 2019-12-06 20:08:01
问题 I want to build a console-like output using JTextPane. Therefore I am using a monospaced font: textpane.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); This works fine for all kind of alphanum (like a-z, 0-9 etc.) characters, but when it comes to symbols like ' \u2588 ' (█), the font isn't monospaced anymore. Did I forgot something? Or isn't there a monospaced font which includes smybols? 回答1: Ok, first off, it sounds to me like you're trying to address a couple of different things here,