jtextpane

Insert a picture into a JTextPane

别来无恙 提交于 2019-12-05 20:47:40
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")!=JFileChooser.APPROVE_OPTION) return; filename = fc.getSelectedFile().getAbsolutePath(); // If no text is entered

How to center text and a JComponent in a JTextPane vertically?

谁说胖子不能爱 提交于 2019-12-05 18:09:04
Currently it looks so What to do so that it looks so? Below is my code: JFrame f = new JFrame(); JTextPane textPane = new JTextPane(); JTextField component = new JTextField(" "); component.setMaximumSize(component.getPreferredSize()); textPane.setSelectionStart(textPane.getDocument().getLength()); textPane.setSelectionEnd(textPane.getDocument().getLength()); textPane.insertComponent(component); try { textPane.getDocument().insertString(textPane.getDocument().getLength(), "text", new SimpleAttributeSet()); } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace()

Changing the background color of a paragraph in JTextPane (Java Swing)

…衆ロ難τιáo~ 提交于 2019-12-05 14:09:41
Is it possible to change the background color of a paragraph in Java Swing? I tried to set it using the setParagraphAttributes method (code below) but doesn't seem to work. StyledDocument doc = textPanel.getStyledDocument(); Style style = textPanel.addStyle("Hightlight background", null); StyleConstants.setBackground(style, Color.red); Style logicalStyle = textPanel.getLogicalStyle(); doc.setParagraphAttributes(textPanel.getSelectionStart(), 1, textPanel.getStyle("Hightlight background"), true); textPanel.setLogicalStyle(logicalStyle); UPDATE: I just found out about a class called Highlighter

Displaying urdu characters in JTextPane

ぃ、小莉子 提交于 2019-12-05 12:31:48
How can I display a single Urdu character in a JTextPane ? I have translated English characters to Urdu characters. But I can't find any way to correctly display those characters into my text component. My goal is to: Get the key pressed on the keyboard. Convert that key into the equivalent Urdu character. Display it in my text component ( JTextPane ). I've completed step 1 and 2 but can't work out the last one. to 3- display it in my text component that is JTextPane source Wikipedia project Encoded in plain UTF-8 import javax.swing.*; import java.awt.*; public class Example { private JFrame

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

丶灬走出姿态 提交于 2019-12-05 09:37:17
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 whole text again. Because even though the HTML generation is not performed in the EDT but in another

Java Print API - Space character incorrectly printed using monospaced 'Courier New' font

笑着哭i 提交于 2019-12-05 06:32:29
Let me first describe the picture below: There are two printed papers. The only difference between them is that few space " " characters from paper in left are replaced by dot "." character in the paper in right. Red line represents the left border to which the text should be aligned Green curve represents my intention to align all characters it connects into a single column. In fact the green curve is supposed to be a vertical line. I want all characters highlighted by the green line to be printed in one column. Font of a String is monospaced Courier New. However, it seems that space

Limit JTextPane memory usage

无人久伴 提交于 2019-12-05 05:36:13
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. just check the content and wipe it accordingly to a maximum buffer size.. since it's a JTextPane you would work on document class used by textpane: void

Monospaced font/symbols for JTextPane

我的未来我决定 提交于 2019-12-05 01:29:37
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? CodeBlind Ok, first off, it sounds to me like you're trying to address a couple of different things here, so I'll try to address them both separately. 1. You need a font that is monospaced for all unicode

Styling text in a JTextArea or JTextPane

泪湿孤枕 提交于 2019-12-04 23:24:58
Basically, I have a JTextPane to hold some text which I wish to style. JTextArea would have been better for me to use but I'm told you cannot style the text in these? However, the JTextPane doesn't seem to style properly. For example, the following code is just returned with the HTML included: public static void main(String[] args) { JFrame j = new JFrame("Hello!"); j.setSize(200,200); JTextPane k = new JTextPane(); k.setText("<html><strong>Hey!</strong></html>"); j.add(k); j.setVisible(true); } I want to be able to just style some text in a JTextPane when a user interacts with the interface,

Using ­ in Java HTML aware Component

一笑奈何 提交于 2019-12-04 17:44:08
I have following problem: I display an HTML-Document with an JTextPane. In my HTML-Text there are ­ (shy at w3.org) to make a soft-hyphenation. My problem is, that no hyphenation appears. Is there some kind of flag, which I don't know, to use these option? Following Programm will show the problem: package com.dvelop.ckue.swing; import javax.swing.*; import javax.swing.text.html.HTMLEditorKit; import java.awt.*; public class SwingGui extends JFrame { public static void main(String[] args) { SwingGui sg = new SwingGui(); sg.setSize(new Dimension(200, 800)); sg.setPreferredSize(new Dimension(200,