0

I would interrupt input from keyboard when i write in jtextpane because before to write a character i would apply a style into a document and after insert this character. I do this with keyListener but every time i press one button on the keyboard the result is two character: one from System.in and one from listener with style.

I hope I explained myself Thanks

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Raul
  • 21
  • 1
  • 4
  • 3
    Use a DocumentListner when you want to be notified of changes to the component or use a DocumentFilter to change or filter what is been send to the field. If you want to add special keys (like ctrl+b), use the key bindings API – MadProgrammer Nov 17 '15 at 21:02
  • DocumentListener is a good solution to apply style but System.in isn't interrupt and i have two input evey moment. – Raul Nov 18 '15 at 09:44
  • Why are you using `System.in` in a GUI!? It's not really the best solution for an event driven environment – MadProgrammer Nov 18 '15 at 10:15
  • i don't use system.in. i'm implementing a complex text editor. When user writes into a JTextPane i would catch character from keyboard with keylistener, apply current style to a character and next insert into textpane, but there are two input: one comes from keyboard and one from my keylistener – Raul Nov 18 '15 at 10:45
  • The solution of MadProgrammer is the one and he should make it an answer. I especially recommend DocumentFilter. – Sharcoux Nov 18 '15 at 15:25
  • DocuemntFilter is what you're looking for – MadProgrammer Nov 18 '15 at 19:30
  • Maybe something like [this](http://stackoverflow.com/questions/14727548/java-change-the-document-in-documentlistener/14727657#14727657) – MadProgrammer Nov 18 '15 at 19:48
  • Thanks to all. i will use documentfilter and seteditable(false) for jtextpane – Raul Nov 19 '15 at 18:24

0 Answers0