• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem whith newline in JTextPane

 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic