jtextpane

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

我们两清 提交于 2020-01-02 05:34:14
问题 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"),

How to make JTextPane scroll horizontally

丶灬走出姿态 提交于 2019-12-29 09:30:10
问题 I have a JTextPane , when there are too many lines, a vertical scroll bar appears, but when a line is too long, instead of appearing a horizontal scroll bar, the line breaks into two lines, how to make the horizontal bar appear instead of breaking into two lines, my jTextPane is added like this: JScrollPane jScrollPane1 = new JScrollPane(); jScrollPane1.setViewportView(jTextPane1); 回答1: As presented here by our very own Rob Camick, you could try using something like... JTextPane tp = new

Swing component flickering when updated a lot

北慕城南 提交于 2019-12-29 09:03:17
问题 I've got a couple thousand lines of code somewhere and I've noticed that my JTextPane flickers when I update it too much.. I wrote a simplified version here: import java.awt.*; import javax.swing.*; public class Test { static JFrame f; static JTextPane a; static final String NL = "\n"; public static void main(String... args) { EventQueue.invokeLater(new Runnable(){ public void run() { f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); f.setSize(400, 300);

Swing component flickering when updated a lot

安稳与你 提交于 2019-12-29 09:02:29
问题 I've got a couple thousand lines of code somewhere and I've noticed that my JTextPane flickers when I update it too much.. I wrote a simplified version here: import java.awt.*; import javax.swing.*; public class Test { static JFrame f; static JTextPane a; static final String NL = "\n"; public static void main(String... args) { EventQueue.invokeLater(new Runnable(){ public void run() { f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); f.setSize(400, 300);

How to set the line spacing in a JtextPane?

南笙酒味 提交于 2019-12-29 08:15:35
问题 First of all, i set the JTextPane like this: HTMLEditorKit editorKit = new HTMLEditorKit(); HTMLDocument document = (HTMLDocument) editorKit.createDefaultDocument(); JTextPane textPane = new JTextPane(); textPane.setContentType("text/html"); textPane.setDocument(document); and i want to set the line spacing in the JtextPane , this is my idea,but it can't work: SimpleAttributeSet aSet = new SimpleAttributeSet(); StyleConstants.setLineSpacing(aSet, 50); textPane.setParagraphAttributes(aSet,

ColorPane - grab strings of different character possible?

喜你入骨 提交于 2019-12-29 02:08:37
问题 I'm currently working on a old project that was given to me, it currently use java swing and has a basic gui. It has a ColorPane that extends Jtextpane to change colors of selected text. It uses this methond public void changeSelectedColor(Color c) { changeTextAtPosition(c, this.getSelectionStart(), this.getSelectionEnd()); } Say that string = "Hello World!" Hello color is green World is black. How do I grab Hello out base on its color from the Jtextpane. I've tried the clunky way which is

How to word wrap text stored in JTextPanes which are cells in a JList

馋奶兔 提交于 2019-12-25 06:43:44
问题 I created a JList that had JTextAreas which word wrapped appropriately when setLineWrap(true); setWrapStyleWord(true); was used. These aren't available for JTextPane and my god forsaken text isn't wrapping. Any advise? 回答1: USe this example to implement your own wrap in JTextPane http://java-sl.com/wrap.html 来源: https://stackoverflow.com/questions/6866627/how-to-word-wrap-text-stored-in-jtextpanes-which-are-cells-in-a-jlist

How to highlight all the text in a JTextPane?

烂漫一生 提交于 2019-12-25 02:33:00
问题 jTextPane1.selectAll(); With the correctly shared events, that command permit to highlight the text in a JTextPane area (I am a bit rusty, I need to not forget to share the "good event focus priorities" ; thank you to : MadProgrammer) 回答1: Since selectAll is a method of JTextComponent , which JTextPane extends from I would take a wild guess and say, probably, yes. Five minutes of coding probably would have gotten you the same answer yourself... Highlighting not seem to appear in the jTextPane

Pressing Ctrl+A is changing the Font in JTextPane

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:06:08
问题 I am creating a simple Text editor using Java Swing with JTextPane component. I have added the code to make the text as Bold, Italics, Underline and also I have added code to get the system fonts in a JComboBox, so that I can change the font of the JTextPane content. And if the content has multiple font styles, it will display the corresponding font name according to the cursor position. I have an issue: if the content has more than one font styles, pressing Ctrl+A is selecting all the

java memory allocation for local variables

独自空忆成欢 提交于 2019-12-24 22:08:46
问题 I have a java application which uses a SerialPortEvent which will be called continously , public void serialEvent(SerialPortEvent evt) { if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE) { try { StringBuilder sBuilder = new StringBuilder(); int length = input.available(); byte[] array = new byte[length]; int numBytes = input.read(array); ....... ...... } i print the array variable contents in a text pane. I have a scenario in which the event will be called continuosly , it makes the