Fórum erro ao alterar texto selecionado no jtextpane. #591756
13/03/2018
0
gente, estou fazendo uma aplicação em java swing, com comunicação com banco phpmyadmin, meu codigo seleciona parte do texto no jtextpane e modifica com um botao para negrito, sublinhado, tachado... usando select e botao que utiliza styleconstants e dps replaceselection, mas na hora que salva no meu banco, salva apenas o texto normal, nao salva as alterações tipo negrito, sublinhado, tachado e tal.... alguem poderia me dar solução?
meu codigo
public class Selecao {
public void formatacao(JTextPane editor, String botao) {
StyledDocument doc = editor.getStyledDocument();
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
if (start == end) {
return;
}
.
if (start > end) {
int life = start;
start = end;
end = life;
}
Style style = editor.addStyle("estilo", null);
switch (botao) {
case "negrito":
StyleConstants.setBold(style, true);
break;
case "italico":
StyleConstants.setItalic(style, true);
break;
case "sublinhado":
StyleConstants.setUnderline(style, true);
break;
case "tachado":
StyleConstants.setStrikeThrough(style, true);
break;
case "link":
// JOptionPane.showInputDialog(null, "Qual o endereço do link?", "Pergunta", JOptionPane.PLAIN_MESSAGE);
editor.replaceSelection("<b>"+editor.getSelectedText()+"</b>");
break;
}
doc.setCharacterAttributes(start, end - start, style, true);
}
}
meu codigo
public class Selecao {
public void formatacao(JTextPane editor, String botao) {
StyledDocument doc = editor.getStyledDocument();
int start = editor.getSelectionStart();
int end = editor.getSelectionEnd();
if (start == end) {
return;
}
.
if (start > end) {
int life = start;
start = end;
end = life;
}
Style style = editor.addStyle("estilo", null);
switch (botao) {
case "negrito":
StyleConstants.setBold(style, true);
break;
case "italico":
StyleConstants.setItalic(style, true);
break;
case "sublinhado":
StyleConstants.setUnderline(style, true);
break;
case "tachado":
StyleConstants.setStrikeThrough(style, true);
break;
case "link":
// JOptionPane.showInputDialog(null, "Qual o endereço do link?", "Pergunta", JOptionPane.PLAIN_MESSAGE);
editor.replaceSelection("<b>"+editor.getSelectedText()+"</b>");
break;
}
doc.setCharacterAttributes(start, end - start, style, true);
}
}

Victor
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)