Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser /text editor Help

 
Lord Byron Canica
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to open a txt file in a JTextArea. I know I have to use the .read() method, but how is executed so that the entire file can be viewed in my textArea? I am trying to create a simple text editor(like notepad) and I can't find any helpful tutorials to help me through this process.
Why does Java make it so hard for you to open and save/write to files. Seems like it should all come standard in a method instead of coding out the process every time?
Any good beginner tutorials for this would be appreciated too!!!
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The text area will most likely need to be nested in a JScrollPane. As for reading and writing, Java makes one way to do it. Can you imagine the fun you'd have if you had to open/read/write files a different way for each context that you wanted to use it in? No, that wouldn't be much fun at all. One way. That's much easier. After about your third time, it only takes about 4 seconds anyways.
Oh, the Swing tutorial will probably be of help to you. It doesn't do much to unify all the components in a giant example that would bring everything together in your brain. But it does a good job, nonetheless.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luckily reading and writing to a file is pretty easy in Java. The I/O and Streams forum would be a good place to ask file I/O questions.
The Swing / JFC / AWT forum would be a good place to ask GUI questions, like working with JTextArea.
Now, you mentioned that you aren't finding any good tutorials. Here is a list of free on-line Java tutorials and books that I have found useful:
  • Sun's Java Tutorial
  • Introduction to Computer Science using Java by Bradley Kjell
  • Introduction to Programming Using Java by David J. Eck
  • Dick Baldwin's Java Programming Tutorials
  • Interactive Programming In Java by Lynn Andrea Stein
  • Bruce Eckel's Thinking In Java
  • JavaRanch's own Campfire Stories
  • Allen B. Downey's How To Think Like A Computer Scientist

  • Take a look at Sun's Java Tutorial, for sections on I/O and Swing.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic