jtextpane

Java Change Color of Element on JTextPane using StyledDocument

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-16 06:04:09
问题 this is kinda overkill for me.. I am using a JTextPane for a chat, I have colors there.. What I want is, with reference to a element changing the color of it.. I am using StyledDocument, I have no clue how to do this.. Thanks in advance ;) 回答1: Use setCharacterAttributes(). Define desired color in a SimpleAttributeSet using StyleConstants.setBackground()/setForeground(). Use Element's start and end offsets for the offset and length. If the last attribute is false only thouse attributes of

inline copy paste JEditorPane HTML

冷暖自知 提交于 2020-01-15 12:33:52
问题 I'm desperatly trying to implement a customized copy/paste in a JTextPane in HTML mode. The most part is working well, I get the html content using EditorKit.write(), I paste it using editorKit.read(). Perfect world. BUT, when I have : <p> test </p> in my editor and I try to copy "es" to obtain <p> tesest </p> , I obtain instead <p>tes</p> <p>es</p> <p>t</p> Knowing that, I m trying to figure out a way to paste "inline" the part supposed to be inline, and in block the part which was in block

inline copy paste JEditorPane HTML

左心房为你撑大大i 提交于 2020-01-15 12:33:19
问题 I'm desperatly trying to implement a customized copy/paste in a JTextPane in HTML mode. The most part is working well, I get the html content using EditorKit.write(), I paste it using editorKit.read(). Perfect world. BUT, when I have : <p> test </p> in my editor and I try to copy "es" to obtain <p> tesest </p> , I obtain instead <p>tes</p> <p>es</p> <p>t</p> Knowing that, I m trying to figure out a way to paste "inline" the part supposed to be inline, and in block the part which was in block

JTextPane or JEditorPane for a Chatroom

空扰寡人 提交于 2020-01-15 04:38:04
问题 I have to make a chatroom like this one : The message displayed also have to show the smileys and everything myst be copy/pastable like in Skype. I don't know what to choose between the JEditor and JTextpane. I tried both I faced the following difficulties : JEditorPane : Copy/Pastable, can show the smileys and copy paste them. I can't set the leftIndent of the message when I set the content to text/html JTextPane : I can set the leftIndent Can't copy/paste the smiley Icons when I set the

Java - Auto-Indentation in JTextPane

泄露秘密 提交于 2020-01-14 10:46:10
问题 I'm making a text-editor in Java, and I have everything I need but auto-indent. How would I make the indentation stay the same if they go to a new line. I'm using a JTextPane for my editor window. Basically, if a user enters a new line, I want the new line to be indented as was the previous. Here is my code for the indentation so far: Note: My JTextPane is txt, and the doc part is the JTextPane's DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); TabStop[]

Get the text content of individual Elements from an HTMLDocument

*爱你&永不变心* 提交于 2020-01-14 10:23:45
问题 I have a jTextPane that has HTMLEditorKit set as the default editorKit . Calling getDocument on the jTextPane returns an HTMLDocument . I can traverse through this Document, navigating around the elements, but I can't seem to find a way to actually get the text contents of individual elements. I know in the DOM, there is a getTextContents() on each element, but I'm not working with the W3C DOM. 回答1: As you traverse the document's ElementIterator , shown here, use the getStartOffset() and

Get the text content of individual Elements from an HTMLDocument

给你一囗甜甜゛ 提交于 2020-01-14 10:23:08
问题 I have a jTextPane that has HTMLEditorKit set as the default editorKit . Calling getDocument on the jTextPane returns an HTMLDocument . I can traverse through this Document, navigating around the elements, but I can't seem to find a way to actually get the text contents of individual elements. I know in the DOM, there is a getTextContents() on each element, but I'm not working with the W3C DOM. 回答1: As you traverse the document's ElementIterator , shown here, use the getStartOffset() and

Write text into a JTextPane with an image background

旧时模样 提交于 2020-01-10 06:07:52
问题 I have a JTextPane with an image for its background. prevWords = new JTextPane() { public void paint(Graphics g) { BufferedImage img; try { img = ImageIO.read(new File("Images/logo.png")); img.getGraphics().setColor(new Color(Color.TRANSLUCENT)); g.drawImage(img, 0, 0, null); } catch (IOException e) { System.out.println("Failed to load logo."); } super.paintComponents(g); } }; When I write text to the the pane, it I cannot see it. I have set the text in pane to be white as well. 回答1: This is

Write text into a JTextPane with an image background

无人久伴 提交于 2020-01-10 06:07:20
问题 I have a JTextPane with an image for its background. prevWords = new JTextPane() { public void paint(Graphics g) { BufferedImage img; try { img = ImageIO.read(new File("Images/logo.png")); img.getGraphics().setColor(new Color(Color.TRANSLUCENT)); g.drawImage(img, 0, 0, null); } catch (IOException e) { System.out.println("Failed to load logo."); } super.paintComponents(g); } }; When I write text to the the pane, it I cannot see it. I have set the text in pane to be white as well. 回答1: This is

Best component in awt/swings to display the webpage and access it

这一生的挚爱 提交于 2020-01-06 16:23:35
问题 Which is the best component in awt/Swings to display the webpage and access the webpage in that component without any issues like (functioning of javascript, images in the page should display good, as viewing the page on browser and support as browser with all functionalities) here there is a tutorial about it displaying webpage but it says,we cannt assure JEditotPane will provide as browser. You can see in the last paragraph of that tutorial. I need to implement that, webpage to be displayed