如何将带有字体和样式的文本文件加载到java中 [英] how can i load a text file with its font and style into java
本文介绍了如何将带有字体和样式的文本文件加载到java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是在java中学习新东西和新库。
现在我要把文本文件加载到JEditorPane中。
Im just learning new stuff and new libraries in java.
what im up to right now is to load a text file into JEditorPane.
-----------------------------------------------------------------------------------
openitem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
try{
int returnvalue=chooser.showOpenDialog(Notepad.this);
if(returnvalue == JFileChooser.APPROVE_OPTION){
File file=chooser.getSelectedFile();
where=file.getPath();
}
FileReader inputFile = new FileReader(where);
BufferedReader bufferReader = new BufferedReader(inputFile);
String line;
while ((line = bufferReader.readLine()) != null){
read+=line+"\n";
}
tf1.setText(read);
startText=read;
bufferReader.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Error while reading file line by line:"
+ e.getMessage());
}
}
});
-----------------------------------------------------------------------------------
和它的好转
但我想要的是如何加载这个txt文件及其字体和样式?????
如果有任何方法可以保存它吗?
任何帮助请。
and its going good
but what i want is how to load this txt file with its font and style?????
and if there is any way to save it too??
any help please.
推荐答案
你需要一个富文本编辑器或所见即所得编辑器。
有几个。
例如:
http://fifesoft.com/rsyntaxtextarea/ [ ^ ]
https://github.com/hoesterholt/JRichTextEditor [ ^ ]
直到开放式办公室的编辑,也可以借用并用于摇摆& SWT GUI。
You need a Rich text Editor or WYSIWYG-Editor.
There are several out there.
Example:
http://fifesoft.com/rsyntaxtextarea/[^]
https://github.com/hoesterholt/JRichTextEditor[^]
up to the Editor of open office, which can also be "borrowed" and used in Swing & SWT GUI.
我使用外包文件将字体样式保存到其中
然后我再次检索它
I used an outsource file to save the font style into it
and then i retrieve it again
这篇关于如何将带有字体和样式的文本文件加载到java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文