| Author |
Problem whith newline in JTextPane
|
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
Hi! I have a keyListener that checks if the user presses the return key this works fine. If the if statement returns true I check to see if I'm in a <ul><li></li></ul> tag. if the user presses return when in a <li></li> it should append a new <li></li> I do this by adding the following code this code works but not as expected. I get a new line between the <li> elements and I want to remove this \n line. How can I do this?
|
SCJP1.4
|
 |
todd runstein
Ranch Hand
Joined: Feb 15, 2005
Posts: 64
|
|
Total guess - have you tried consuming the KeyEvent? if( ke.getKeyChar() == KeyEvent.VK_ENTER ){ if( inElement( HTML.Tag.LI ) ){ ..... code ..... ke.consume(); } } Worth a shot!
|
 |
Ken Blair
Ranch Hand
Joined: Jul 15, 2003
Posts: 1078
|
|
Originally posted by todd runstein: Total guess - have you tried consuming the KeyEvent? if( ke.getKeyChar() == KeyEvent.VK_ENTER ){ if( inElement( HTML.Tag.LI ) ){ ..... code ..... ke.consume(); } } Worth a shot!
That would be it I'm sure. The JTextPane receives the event still and inserts a new line. Consuming the event will put a stop to that.
|
 |
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
Thanks, but that didn't help. It still is a line between the <li></li> and the next </li></li> looks like this if we view the HTML source If i go intor the source and remove the \n line then the code will produce 2 dots in the WISWYG editor( when viewing the text in the JTextPane without seeing the HTML tags ) every time i hit the return but when I view the html source it's just 1 <li></li> ?? here is the javacode that handles the and here is the check method really hope you can help me
|
 |
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
|
|
After some testing I put the code in the keyPressed method instead of the keyTyped method and the consume() method worked? Is this the right way to do it or is there a muh better solution?
|
 |
 |
|
|
subject: Problem whith newline in JTextPane
|
|
|