0

i am creating a text editor using java swings concept
this is the code i am using to save a file

jfr.setTitle(fname.getName());
FileOutputStream fop=new FileOutputStream(fname);
fop.write(jta.getText().getBytes());
fop.flush();
fop.close();

where fname is the name given in save file chooser bye the user
jta is the text pane in which the text to be saved...
my problem is that it is saving the text but not the font style,color,etc...

how to do it .. i am stuck here,please help me...

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by JamesCherrill
0

If you are saving the text area to one of these files then they don't have fonts and sizes. That is up to the editor you are using to view the file.
.txt for example doesn't have colors.

0

i am typing some content with some styles and saving it,when i open it again i am unable to see the font styles which i have specified to them.

0

i am typing some content with some styles and saving it,when i open it again i am unable to see the font styles which i have specified to them.

That is because you are not saving the style. How are you suppose to see it?
You can try to create a separate file,for each text file, in which you will save specific information of the style. When you open the text file, also read the "style" file and adjust the fonts accordingly

0

i am new to java programming,can u say me how to create a separate file,for each text file, in which you will save specific information of the style. When you open the text file, also read the "style",,please??

0

In the same way you are saving and reading the file your are using now.
Only this time the other file will have data like:

color=255,0,0
// or color=red
font=5

And others. When you read the file with the text, you will also read the second file. Take the data and apply the style.

You should use BufferedReader in order to read the second file line by line. You will also use the String class to separate the name from the values:
color=red

For the file name, if the text file is called something like:
file.txt, then you can have the other called: file_style.stl

0

You could use an HTMLDocument as the document model for a JTextPane, then you can easily read/write the formatted content from/to .html files.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.