jtextpane

JTextPane highlight multiple words

不问归期 提交于 2019-12-24 20:05:22
问题 I'm trying to highlight multiple words in jTextPane but with no luck. So far I made this: Highlighter h = jTextPane1.getHighlighter(); h.removeAllHighlights(); String text = jTextPane1.getText(); String words[] = text.split(" "); for(int i = 0;i<words.length;i++){ String temp = words[i]; if(temp.equals("word")){ try{ h.addHighlight(i, temp.length(), DefaultHighlighter.DefaultPainter); } catch(Exception e){ } } } But this only highlights the first word. How to select all found words? 回答1:

JTextPane is scrolling its parent Scrollpane to the bottom

笑着哭i 提交于 2019-12-24 13:19:09
问题 Here is a littel SSCCE which shows the weird scrolling behaviour. When you start it, it scrolls down to the bottom of the scrollpane. But I want it to stay on top. So far I found out, this only happens with JTextPanes and not even with JTextArea. It also only happens if you are on the EDT. Remove the invokeLater() from the SSCCE and it works as expected. However, that's not a solution (for me). I also tried that, but with no effect: final DefaultCaret caret = (DefaultCaret) tp.getCaret();

Java Swing: Mouse cursor misbehaves when held over a rectangle

。_饼干妹妹 提交于 2019-12-24 12:28:00
问题 I need to change the cursor while it moves over an array-list of rectangles by the contain(p) method.The problem is My first algorithm to use an iterator to iterate through the rectangles doesn't work as expected.The cursor only changes when hovering over the first rectangle,in the other rectangles neither does it respond by showing the cursor changing nor indicate through the console that the cursor is hovering above them?!! My second solution also refuses to work properly.I use a for loop

JTextPane and Horizontal Lines

牧云@^-^@ 提交于 2019-12-24 10:55:17
问题 How would I go on creating a horizontal line element in JTextPane? Just a rectangle painted probably by View.paint(Graphics), which covers the whole width of the JTextPane, and has an arbitrary height. I also need to be able to dynamically remove these elements. I'm attempting to approach this by creating a custom editor kit, which has a custom view factory, which returns a "HorizontalLineView" for line elements... but I must admit that this all is a bit over my head! How do I, for example,

How to make JTextPane wrapped in JScrollPane shrink to fit the text

柔情痞子 提交于 2019-12-24 10:29:00
问题 I have a JTextPane with HTML text. I used GroupLayout (using WindowBuilder). I've set the minimum size of my JFrame to 800x600 so the user cannot make it smaller than that. The app has a big scrolling JPanel the size of the entire window. The top part of the panel is taken up by a JTextPane wrapped in JScrollPane . I have disabled the scroll bars and sized the JScrollPane to make the entire text visible. In group layout the JScrollPane is set to stay constant vertically, but size horizontally

JTextPane line break

最后都变了- 提交于 2019-12-24 07:13:23
问题 In this question, the inquirer says The JTextPane do have word wrap when text exceeded width This does not seem to be the case. scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); this.contentPane.add(scrollPane); txtrFghj = new JTextPane(); txtrFghj.setBorder(null); txtrFghj.setContentType("text/html"); txtrFghj.setText(content); scrollPane.setViewportView(txtrFghj); In the given code excerpt, content 's content will not

how to append css/html table in jtextpane

你。 提交于 2019-12-24 06:43:37
问题 I'm trying to 'append' an css/html table to a jtextpane. When I do: setText like this: jtextpane.setText(css) I get the desired result [perfect!]: but when I try to append the text to the jtextpane like this: int len = jtextpane.getDocument().getLength(); jtextpane.setCaretPosition(len); jtextpane.replaceSelection(css); I get the html code embedded like this: Q: how to append table's result (not the code) in the jtextPane? I assume I'm doing something wrong with the replaceSelection?! Thanks

Select multiple items in JTextPane

放肆的年华 提交于 2019-12-24 05:44:06
问题 I would like to highlight(select) multiple occurrences of a string in JTextPane . I would like to make something like findall. Here is what I have written. int a=0; while(jTextPane1.getText().indexOf(search,a)>0) { int i =jTextPane1.getText().indexOf(search,a); a=i+search.length(); jTextPane1.select(i,a); } It works ok, but the problem is that it highlights only the last occurrence, because the highlight changes. I would like to make multiple highlights. 回答1: I think that tutorial about

Read JTextPane line by line

自古美人都是妖i 提交于 2019-12-23 23:26:37
问题 Is there a way to read the contents of a JTextPane line by line? Much like the BufferedReader? 回答1: Element root = textPane.getDocument().getDefaultRootElement(); Once you get the root Element you can check to see how many child elements (ie. lines) exist. Then you can get each child Element and use the start/end offset methods to get the text for that particular line. This would be more efficient than getting all the text in one big string and then splitting it again. 回答2: The way that I've

JTextPane: KeyBindings are not working on StyledEditorKit

半世苍凉 提交于 2019-12-23 18:06:05
问题 Please have a look at the following code import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import javax.swing.text.*; public class Form1 extends JFrame { private JTextPane textPane; private JPanel south; private JScrollPane