Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-11-2008, 10:42 PM
Member
 
Join Date: Jan 2008
Posts: 39
mcal is on a distinguished road
Text Area problem
Hi guys!

I have used a text area to display the contents of a textfile. I am trying to write some code so that when the data is displayed, i can add more data to this file, just by typing in the text area. I have set the setEditable to true, and this lets me edit the data. But the problem is that when i close the text Area which is displayed in a dialogue box, the edited data isn't saved. What can i do?

This is the code i have written:
Code:
import java.awt.BorderLayout; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import javax.swing.JDialog; import javax.swing.JTextArea; import java.awt.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.event.ActionListener.*; import java.util.*; import java.io.*; import javax.swing.*; import java.util.Calendar; import java.awt.image.*; import javax.imageio.*; public class notes { private JTextArea textArea; public notes() { super(); try{ JDialog dialog = new JDialog(); dialog.getContentPane().setLayout(new BorderLayout(10, 10)); String record = null; File file = new File("notes.txt"); FileInputStream fileInput = new FileInputStream(file); DataInputStream dis = new DataInputStream(fileInput); BufferedWriter w; w = new BufferedWriter(new FileWriter("notes.txt")); String string = dis.readLine(); textArea = new JTextArea(); while(string != null){ textArea.append(string + "\n"); string = dis.readLine(); textArea.setBackground(Color.pink); textArea.setFont(new Font("Times New Roman", Font.BOLD, 14)); textArea.setEditable(false); textArea.write(w); textArea.setForeground(Color.blue); } dialog.getContentPane().add(BorderLayout.CENTER, textArea); dialog.setTitle("Notes"); dialog.setSize(800, 900); dialog.setVisible(true); }catch (Exception e){ e.printStackTrace(); } } public static void main(String[] args){ new notes(); } }
Thanks a lot
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Text Editor mustahsan4u New To Java 2 03-26-2008 03:34 PM
Accessing Japanese characters from text area princy.mat Advanced Java 0 03-08-2008 04:11 PM
Displaying data into text area abhiN New To Java 1 01-22-2008 11:30 AM
textfiled and text area to UTF-16? Mr tuition AWT / Swing 0 12-04-2007 01:40 PM
problem trying to view the contents of a text file in JTextArea warship AWT / Swing 0 07-17-2007 04:30 PM


All times are GMT +3. The time now is 05:01 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org