• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Editing a text file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a text file, which I can read and write to, but I want to know if there is an easy way to delete text (one line at a time) from a GUI, without the user editing it directly themselves(i.e. selecting the text somehow(Haven't figured this out either) then click a button, and it magically disappears in the file). Currently I have the text displayed in a JTextArea which is in a JScrollPanel.
 
Wes Beere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While awaiting a reply, I finally figured out how to select text, and identify it, but I still need to find out how to edit the file, preferably without rewriting the whole thing every time.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Wes Beere:
I still need to find out how to edit the file, preferably without rewriting the whole thing every time.

That's essentially your only option. Technically, you only have to rewrite the file starting from the point where the text was deleted. This is why most applications save to disk only when the user tells them to.
 
Wes Beere
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I think I've figured out an easy way to do that now too, using lists to hold each line while they are being edited, then write the list when the user is done.
 
bacon. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic