Olá,
Quero fazer um editor de texto usando o JeditorPane, mas não consigo abrir um arquivo nem salvar…
o metodo funciona com um JtextArea porem com o editorPane o texto não é carregado.
sds
Olá,
Quero fazer um editor de texto usando o JeditorPane, mas não consigo abrir um arquivo nem salvar…
o metodo funciona com um JtextArea porem com o editorPane o texto não é carregado.
sds
Dá pra você ler o arquivo e mandar carregar no JEditorPane.
Sim mas o carregamento no editorpane não está funcionando
private void m_openActionPerformed(java.awt.event.ActionEvent evt) {
// Arquivo.
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(editorPane);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would open the file.
try {
// Abre o arquivo para leitura e pega seu conteúdo
FileInputStream inputFile = new FileInputStream(file);
byte fileContent[] = new byte[(int)file.length()];
inputFile.read(fileContent);
String strFileContent = new String(fileContent);
inputFile.close();
} catch (Exception e) {
System.out.println("Não conseguiu abrir o arquivo: "+e.getMessage());
}
}
}
private void m_salvarActionPerformed(java.awt.event.ActionEvent evt) {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(editorPane);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
FileOutputStream outputFile = new FileOutputStream(file);
// outputFile.write("qualquer coisa");
outputFile.close();
} catch (Exception e) {
System.out.println("Não foi possível salvar o arquivo: "+e.getMessage());
}
}