jtextcomponent

DocumentFilter: Why is replace() invoked and not insertString()?

北战南征 提交于 2020-12-30 09:47:18
问题 I've implemented a DocumentFilter subclass, and when I type text into the JTextComponent , the replace() method of the filter is invoked, and not insertString() (which is never invoked). Any idea why that is? 回答1: The insertString(...) method is invoked when you update the Document directly, by using the Document.insertString(...) method. The replace(...) method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes

DocumentFilter: Why is replace() invoked and not insertString()?

风格不统一 提交于 2020-12-30 09:46:38
问题 I've implemented a DocumentFilter subclass, and when I type text into the JTextComponent , the replace() method of the filter is invoked, and not insertString() (which is never invoked). Any idea why that is? 回答1: The insertString(...) method is invoked when you update the Document directly, by using the Document.insertString(...) method. The replace(...) method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes

JTextComponent inside JPanel inside JScrollPane

元气小坏坏 提交于 2020-01-15 21:02:01
问题 I recently have had the need to put several Components, a JTextPane among them, inside of a single JScrollPane's viewport view. (See details here, if interested). I put all the Components (two JPanels and the JTextPane) inside of another JPanel, this one having a BorderLayout LayoutManager, and set that JPanel as the ScrollPane's viewport view. What I immediately noticed was: The JTextPane doesn't resize its width according to the width of the JScrollPane anymore, even when the JScrollPane is

JTextComponent inside JPanel inside JScrollPane

↘锁芯ラ 提交于 2020-01-15 20:58:16
问题 I recently have had the need to put several Components, a JTextPane among them, inside of a single JScrollPane's viewport view. (See details here, if interested). I put all the Components (two JPanels and the JTextPane) inside of another JPanel, this one having a BorderLayout LayoutManager, and set that JPanel as the ScrollPane's viewport view. What I immediately noticed was: The JTextPane doesn't resize its width according to the width of the JScrollPane anymore, even when the JScrollPane is

JTextComponent inside JPanel inside JScrollPane

↘锁芯ラ 提交于 2020-01-15 20:56:10
问题 I recently have had the need to put several Components, a JTextPane among them, inside of a single JScrollPane's viewport view. (See details here, if interested). I put all the Components (two JPanels and the JTextPane) inside of another JPanel, this one having a BorderLayout LayoutManager, and set that JPanel as the ScrollPane's viewport view. What I immediately noticed was: The JTextPane doesn't resize its width according to the width of the JScrollPane anymore, even when the JScrollPane is

Underline StyleConstant in a different colour with AttributeSet

≡放荡痞女 提交于 2020-01-15 15:29:54
问题 I am implementing a spellchecker and wondered if there is an easy/obvious way of underlining some text in a different colour such as Red. I have everything set up and underlining with the following code (also sets the color of the text): private AttributeSet getAttributeSet(Color foregroundColor) { SimpleAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setForeground(attrs, foregroundColor); StyleConstants.setUnderline(attrs, true); } The above code sets the word to blue but also

Coloring texts in java

风格不统一 提交于 2020-01-15 06:54:05
问题 I have a file which i will read it line by line. Split each line into words by using the split method and color the words based on their positions (first 4 chars of each line etc) and also based on the words. Different color should be applied to different words like below. I want to know which class is useful, i looked into highlighter. Any suggestions, with example would be very helpful String text = textArea.getText(); String newLine = "\n"; String spaceDelim = "[ ]+"; String[] tokens;

browse html files in java swing [duplicate]

霸气de小男生 提交于 2020-01-14 14:39:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Swing JDialog/JTextPane and HTML links I want to browse HTML files in swing and I have done that, the content of html file is being displayed with the help of JEditorPane but links of html file are not opening another HTML file into the same pane. Is it possible in swing? I want the html file should treat like pure HTML files means link should work there in JAVA editor pane also currently i am using the

How to set DocumentFilter with input length and range? e.g. 1-3 or 10-80

∥☆過路亽.° 提交于 2020-01-09 12:12:12
问题 I'm using DocumentFilter to restrict input as integer or decimal. And the code I post here is working well for that. Can anybody help me about how to restrict the input length or range in the given code? Thanks!! class MyIntFilter extends DocumentFilter { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb

How to set DocumentFilter with input length and range? e.g. 1-3 or 10-80

我只是一个虾纸丫 提交于 2020-01-09 12:04:28
问题 I'm using DocumentFilter to restrict input as integer or decimal. And the code I post here is working well for that. Can anybody help me about how to restrict the input length or range in the given code? Thanks!! class MyIntFilter extends DocumentFilter { public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb