• 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

JTextField + JTextArea -> Problem with backspace-ing

 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was working on simple Swing application, and I got stuck - again! The application is something similar to Windows Command Prompt.
This is the deal now:
I have a JTextField where user can enter command; the response is shown in the JTextArea above it.
I am waiting for the command in the field until user presses Enter key. After that some logic is invoked, and result is displayed inside of JTextArea. I also have one more event assocciated with JTextField - when any key is pressed, character pressed is appended to text in JTextArea, so it lookes like user is typing command in JEditorPane. And now, I don't know how can I make application remove last entered characted from JTextArea if user presses Backspace (just in case user wants to change/correct entered command)?
One way might be to retreive all the text from text area, then "manually" remove last character and then set new text again. But, I was wondering if there is a "more ellegant" way to do that?

Thanks!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get the field's Document and use remove and getLength to remove the final character.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the solution, someone might use the idea later:



@Rob: Thanks for directions!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic