jtextpane

Java - Is it possible to define different alignment in JTextPane?

╄→гoц情女王★ 提交于 2019-12-13 05:26:28
问题 I have JTextPane which contains html, I define my own JTextPane class as follow: public class MyPane extends JTextPane { static SimpleAttributeSet Format2 = new SimpleAttributeSet(); static SimpleAttributeSet Format1 = new SimpleAttributeSet(); static { StyleConstants.setForeground(Format1, Color.black); StyleConstants.setLeftIndent(Format1, 5); StyleConstants.setRightIndent(Format1, 5); StyleConstants.setSpaceAbove(Format1, 0); StyleConstants.setSpaceBelow(Format15); StyleConstants

How to fix size of JTextPane to its content?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 05:19:34
问题 I have JPanel with BoxLayout . panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS){ /** * */ private static final long serialVersionUID = 1L; @Override public Dimension minimumLayoutSize(Container target){ return new Dimension(100, 25); } @Override public Dimension maximumLayoutSize(Container target){ return new Dimension(100,25); } }); I add some JTextPane and JPanel to it dynamically. I call the method below to add new JTextPane to my jpanel and pass the text to it. public void display

making text underline font by using JTextPane?

风格不统一 提交于 2019-12-13 04:47:25
问题 I have a class with the name of fontlist and I want to make a underline font with the use of JTextPane but I find some difficulty to get this. Both bold or italic works properly but when i added underline code then its give me some error. My Code is : import java.awt.*; import java.awt.font.TextAttribute; import javax.swing.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.text.*; import javax.swing.text.*; import javax.swing.event.*; import javax.swing.plaf.basic

Trying to get the start and end point of each line within a text pane

送分小仙女□ 提交于 2019-12-13 03:58:18
问题 Trying to get the start and end point of each line within a text pane: The text pane contains (note target is the end of each line not including the blank space line): (blank space line) MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDKVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtarget

How to make the horizontal scroll bar appear in a JScrollPane that contains a JTextPane component

百般思念 提交于 2019-12-13 01:30:21
问题 I can't make the horizontal scrollbar appear. I've tried using JTextPane.setSize(), JTextPane.setPreferredSize() and no size method for JTextPane. I'm also using JScrollPane.setPreferredSize(). The vertical scroll bar appears, but the horizontal one doesn't. Here is an example: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Test { private int textPaneWidth = 500; private int textPaneHeigth = 200; private int scrollPaneWidth = 100; private int scrollPaneHeigth =

Is it possible for JTextPane to have columns and rows?

孤街浪徒 提交于 2019-12-12 17:06:12
问题 I have JTextPane from Netbeans designer's section. I want to add columns and rows on it. However, there is no option for adding columns or row in the property window of JTextPane . Is there another way to do this? 回答1: JTextPane supports formatted documents. One format it supports is HTML. Therefore, it is possible to use an HTML table to provide tabular data - data in columns and rows. Also consider using a JTable, which (of course) has inbuilt support for columns and rows. 回答2: JTextPane is

Aligning and Inlining components (or icons) in JTextPane

喜你入骨 提交于 2019-12-12 14:12:44
问题 I'm working on an application in Java which, among other things, is supposed to display the details of a Magic: The Gathering card in a text field (since I'm using Swing, this is currently a JTextPane ). Those details contain text and small icons, with some of those icons inlined with the text (so the text flows around them), and some icons, by my design, right-aligned with some left-aligned text in the same line. I took an image from another application which uses a very similar design to

Multi-color text selection in JTextPane (Swing)

删除回忆录丶 提交于 2019-12-12 12:31:37
问题 I have a JTextPane, with styledDocuent. I've inserted programmatically the text: "Hello World". Word "Hello" is red, and word "World" is green. Is there any way I can select the two words, and the selection rectangle becomes half red half green(or whatever color the selected character is)? By select, I mean, select text at runtime, not programmatically... I believe here Changing color of selected text in jTextPane , StanislavL tells how this can be achieved, by I don't know how to implement

How to add images in JTextPane?

你说的曾经没有我的故事 提交于 2019-12-12 11:25:32
问题 I want to give the user the facility to copy and paste Images in JTextPane . Please help me. 回答1: There is an easy way to add an image: JTextPane pane = new JTextPane (); pane.insertIcon ( new ImageIcon ( "/path/to/image.png" ) ); But there is no simple way to copy an image from the pane, since it cannot be selected and cannot be easily located in the pane document. 回答2: You need a StyledDocument, like resulting from HTML. Hence set the content type to "text/html". Then <img src="file:...">

Disable editing in a JTextPane while allowing visible cursor movement

爷,独闯天下 提交于 2019-12-12 11:23:25
问题 I have a JTextPane which is populated by reading from a file, after which the data is parsed and formatted. The user is not allowed to edit the JTextPane , but I want them to be able to navigate in it with a visible cursor. If I use setEditable(false) , the cursor is invisible, although it is possible to indirectly observe the position of the invisible cursor by holding down Shift and using the arrow keys to select a block of text. To enable a visible cursor while disallowing editing, instead