jtextpane

JTextPane HTML renderer wrong?

隐身守侯 提交于 2020-01-06 15:29:10
问题 I have a JTextPane and want to create a div within it, with exactly the height of the JTextPane. The div should be always the height of the JTextPane. public class Test { JTextPane edit=new JTextPane(); public Test() { JFrame frame=new JFrame("Center text vertically"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(edit); String text = "<html><div style=\"height: 0px; border: 1px solid black;\">here is some text</div></html>"; edit.setEditorKit(new

BadLocationException when using Utilities.getRowStart On hit of Enter key

廉价感情. 提交于 2020-01-06 07:45:09
问题 I am using Utilities.getRowStart to find out the number of lines in a JTextPane . But it gives the BadLocationException when I hit the enter key: javax.swing.text.BadLocationException: Position not represented by view Any idea? int offset = pane.getText().length(); while(offset > 0) { try { offset = Utilities.getRowStart(pane, offset) - 1; } catch (BadLocationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } lineCount++; } 回答1: int offset = pane.getText().length();

How to get current html element(tag) in JTextPane?

微笑、不失礼 提交于 2020-01-05 04:33:33
问题 I am doing on WYSIWYG Html Editor using Java Program. I need When I click mouse on Paragraph element, It should be displays tag in JOption dialog. Please advice me How can i do this? 回答1: See for example this one http://java-sl.com/JEditorPaneStructureTool.html In simple words you can get your HTMLDocument and get paragraph using getParagraphElement() method. Use viewToModel() method of JEditorPane to get caret offet for the clicked point. 来源: https://stackoverflow.com/questions/10533940/how

Make a selected word bold in the text of a HTML-styled JtextPane?

旧时模样 提交于 2020-01-05 03:07:46
问题 How can I get the selected word in the text from a JTextPane and then apply the Bold property for the selected-text by using the Ctrl+B Short Cut. String are given to the JTextpane from the xml files. String are get from the tag elements and set to the JTextpane : String selectedText = ta_textpane.getSelectedText(); int getselectedtextstart = ta_textpane.getSelectionStart(); int getselectedtextend = ta_textpane.getSelectionEnd(); String textbef = text.substring(0, getselectedtextstart);

Loading custom fonts at runtime for use with JTextPane

感情迁移 提交于 2020-01-04 06:14:49
问题 Thanks for your time. My question is regarding the display of different fonts within the one JTextPane. My client wishes to view a word in two different languages within the one field. They've explicitly specified that they wish the different languages (namely Amharic, Arabic, Coptic and Hebrew) to be shown with different fonts. These are obviously non-standard fonts and I can't rely on the user having the required fonts installed on their OS. From my research I've found that I can load a

Style a JTextPane to have console-like formatting?

人盡茶涼 提交于 2020-01-04 04:45:10
问题 Is there a way to make the text in a JTextPane look similar to that of console output? By that I mean, basically, how each character is the same width, so that things like ASCII art, or spacing indentation would work correctly. For example, currently, if I type "First" and then 5 spaces, and then on a new line "Second" and then 4 spaces, the two lines do not end in the same position, so if there was text following those spaces, the text would not be aligned. I don't know if it changes

JTextPane and Hanging Indent Glitch

佐手、 提交于 2020-01-04 03:38:28
问题 I'm facing an annoying little bug with JTextPane and hanging indent. Here's a simple example: public class Scrap { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setLayout(new BorderLayout()); JTextPane textPane = new JTextPane(); JScrollPane scroll = new JScrollPane(textPane); frame.add(scroll); StyledDocument doc = (StyledDocument) textPane.getDocument(); try { String str = "Lorem

Font of a StyledDocument associated with a JTextPane

烂漫一生 提交于 2020-01-04 02:42:24
问题 What font does the StyledDocument associated with a JTextPane use? By default, does it use the same font as the JTextPane? In particular, I'm wondering about the font size. 回答1: StyledDocument is just interface. Interface doesn't have any font. If you take a look at the DefaultStyledDocument class (implementing the interface). public Font getFont(AttributeSet attr) { StyleContext styles = (StyleContext) getAttributeContext(); return styles.getFont(attr); } Then in the StyleContext's sources

JTextPane indentation

孤街浪徒 提交于 2020-01-03 19:01:17
问题 Is there a way to indent a block of text in a JTextPane ? import javax.swing.*; import java.awt.*; import javax.swing.text.StyledDocument; public class SimpleTextPane { public static void main(String... args){ JFrame frame = new JFrame(); JTextPane textPane = new JTextPane(); textPane.setPreferredSize(new Dimension(400, 400)); StyledDocument doc = textPane.getStyledDocument(); try { doc.insertString(doc.getLength(), "Now he has departed from this strange world a little ahead of me. That means

JTextPane indentation

随声附和 提交于 2020-01-03 18:59:20
问题 Is there a way to indent a block of text in a JTextPane ? import javax.swing.*; import java.awt.*; import javax.swing.text.StyledDocument; public class SimpleTextPane { public static void main(String... args){ JFrame frame = new JFrame(); JTextPane textPane = new JTextPane(); textPane.setPreferredSize(new Dimension(400, 400)); StyledDocument doc = textPane.getStyledDocument(); try { doc.insertString(doc.getLength(), "Now he has departed from this strange world a little ahead of me. That means