Results 1 to 11 of 11
- 12-26-2008, 04:15 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
text areas, printstream, and "\n"
Hey all. I'm almost done with my notepad program - there's just two tiny problems.
1) I used this code to save my files:
Java Code:Scanner tScan = new Scanner(area.getText()); output.print(tScan.nextLine()); while(tScan.hasNextLine()) { output.print("\n" + tScan.nextLine()); }
2) Also - how do I edit the title in the titlebar of my JFileChoosers? I tried to send it as the second parameter, as I had seen done in code I looked up, but it didn't work.
- 12-26-2008, 04:24 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
Did you try to workout with the system properties for the new line? Something like this,
Java Code:System.getProperty("line.separator");
- 12-26-2008, 04:31 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
Oh dang, I don't think my course/book covered that. Could you explain to me how I would use that?
-
what if instead you tried something simple like
Java Code:area.write(output);
This allows the JTextArea itself to store its contents into the Writer stream that is passed as a parameter.
- 12-26-2008, 05:04 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
Thanks man. Just put that in. It's now working - got the spaces/new lines working. But now it's not saving as a txt file anymore, even though I used addChoosableFileFilter with my text filter which only accepts ".txt" files. How do I fix that? Now it's just saving as a generic file :(, though it works when I open it with notepad.
Also how do I set the title of the file chooser?Last edited by diggitydoggz; 12-26-2008 at 05:07 AM.
- But now it's not saving as a txt file anymore,
even though I used addChoosableFileFilter with my text filter which only accepts ".txt" files. How do I fix that?
Now it's just saving as a generic file , though it works when I open it with notepad.
Also how do I set the title of the file chooser?Last edited by Fubarable; 12-26-2008 at 05:48 AM.
- 12-26-2008, 05:50 AM #7
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
Thanks. Yeah my bad. Got a little lazy. I figured the last two out. Program complete... onto the next project: hangman.
-
You're welcome, and good luck with your hangman project.
- 12-26-2008, 01:54 PM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
First of all read about the System class.
Here is the link.
Keep your eye on getProperty() two overloaded methods.
Then look at the following list.
Java System Properties
- 12-26-2008, 04:14 PM #10
Member
- Join Date
- Dec 2008
- Posts
- 55
- Rep Power
- 0
gotcha... I had to add "\r\n" to the front of the string instead of just "\n". I had already finished it using the FileWriter that Fuburable helped me out with but I decided to try to rewrite it using the line.separator instead and it works too. Thanks for the help man... this will come in handy.
- 12-26-2008, 05:03 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 25
If you know to do the same thing different ways, best way that a developer can achieve. Seems you too... :)
Similar Threads
-
Hwlp with "Open", "Save", "Save as..."
By trill in forum New To JavaReplies: 3Last Post: 11-02-2010, 10:26 AM -
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 04:03 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 08:35 AM -
<core:forEach var="" begin="+<%=j%>+">???
By freddieMaize in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 09-27-2008, 02:20 AM -
"Jumble" or "Scramble" Program
By Shadow22202 in forum Java AppletsReplies: 8Last Post: 04-30-2008, 04:42 AM
Bookmarks