aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Problem whith newline in JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Problem whith newline in JTextPane" Watch "Problem whith newline in JTextPane" New topic
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem whith newline in JTextPane
 
Similar Threads
Change attribute of UL element
Inserting Ordered List in JEditorPane
textfield that accepts only numbers???
About KeyEvent?
Unable to add Labels with Image to Panel thru KeyListener.