Results 1 to 4 of 4
- 04-30-2012, 05:51 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 1
- Rep Power
- 0
JTetPane changing text colour help
Hi everyone, i'm new and I am struggling with a problem, please anyone help.
I created a GUI using JTextPane and i've got it working, I have created a working trie tree and I am trying to implement a realtime spellchecker.
What my program does according to my logic at the moment is if a word is not found in my trie, the word is changed to the color red.
I know my trie is working because I system out the words that aren't in the TRIE and it does so correctly. Now when I go into the if statement for when a word isn't in the trie I try the setCharacterAttributes method on the word from its starting index to the end of the word. the indexes work because I output them too and they are correct, I counted them myself to make sure, here is my code:
Oh and by the way this is when I open an existing text file.Java Code:System.out.println("Misspelled words: "); int indexS = 0, indexE = 0; String all = createGui.ta.getText(); SimpleAttributeSet attrs = new SimpleAttributeSet();; StyleConstants.setForeground(attrs, Color.red); StyledDocument doc = createGui.ta.getStyledDocument(); while(true) { readWord(fIn); if(!trie.found(s)) { indexS = all.indexOf(s.toLowerCase()); System.out.println(s + " on line: " + lineNum); indexE = indexS+s.length()-1; System.out.println("indexS is at: " + indexS); System.out.println("indexE is at: " + indexE); doc.setCharacterAttributes(indexS,indexE, attrs, false); } if(ch == -1) break; }
Here is the GUI and output I receive from netbeans:


As you can see it isn't highlighting correctly, I'm not sure why, please help I've been struggling for hours.
- 04-30-2012, 06:24 PM #2
Re: JTetPane changing text colour help
To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. No spellcheck code, just a JTextPane populated with some text, and a button with an ActionListener that finds and highlights certain words in the text pane. Include your debug sysouts in the SSCCE.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-30-2012, 06:29 PM #3
Re: JTetPane changing text colour help
Crossposted: JTextPane changing text color issues
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-30-2012, 07:16 PM #4
Similar Threads
-
How to underline text using a different colour
By Jack_Maloney in forum AWT / SwingReplies: 3Last Post: 02-07-2012, 10:33 PM -
changing JFrame colour
By simo_mon in forum AWT / SwingReplies: 0Last Post: 08-08-2009, 02:15 AM -
Changing text colour in code
By dbashby in forum New To JavaReplies: 2Last Post: 04-29-2009, 03:32 PM -
[SOLVED] Change text colour on conditions in netbeans
By dbashby in forum New To JavaReplies: 0Last Post: 03-26-2009, 01:23 AM -
Changing the color of text
By Lang in forum New To JavaReplies: 1Last Post: 11-04-2007, 09:51 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks