Есть методы изменения цвета выделенного текста.
// выбираем цвет
private void showColorChooser() {
colorChooser = new JColorChooser();
if (textColor == null) {
textColor = Color.BLACK;
}
textColor = colorChooser.showDialog(null, "Цвет текста", textColor);
colorChoseButton.setBackground(textColor);
colorChoseButton.setForeground(textColor);
if (textPane.getSelectedText() == null) {
textPane.setForeground(textColor);
}
}
// меняем цвет текста
private void changeTextColor(Color c) {
document = textPane.getStyledDocument();
SimpleAttributeSet colorSeter = new SimpleAttributeSet();
StyleConstants.setForeground(colorSeter, c);
document.setCharacterAttributes(textPane.getSelectionStart(), textPane.getSelectionEnd() - textPane.getSelectionStart(), colorSeter, true);
textColor = colorChoseButton.getBackground();
textPane.setSelectedTextColor(textColor);
}
Есть метод saveFileAs();
private void saveFileAs (){
JFileChooser fileChooser = new JFileChooser();
fileChooser.showDialog(null,"Save");
file = fileChooser.getSelectedFile();
if (fileChooser.getSelectedFile()==null || textPane.getText()==null){
JOptionPane.showMessageDialog(null, "Файл не выбран или пуст");
} else {
try {
outputStream = new FileOutputStream(file);
outputStream.write(textPane.getText().getBytes());
} catch (IOException ex){}
}
}
Я меняю цвет текста и сохраняю его в файл формата .dock. Открываю файл с помощью word и его цвет черный (не поменянный). Как это исправить?
JTextArea
умеет сохранять документы в формате doc? МетодgetText()
возвращает обычную строку и создаете вы обычный текстовый файл