StyledDocument로 사용할 수있는 스타일이 지정된 텍스트 (문자의 색상 속성 포함)는 JTextPane 및 JEditorPane에서 사용할 수 있습니다. 따라서 JTextPane을 사용하십시오.
private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
StyledDocument doc = textPane.getStyledDocument();
int start = textPane.getSelectionStart();
int end = textPane.getSelectionEnd();
if (start == end) { // No selection, cursor position.
return;
}
if (start > end) { // Backwards selection?
int life = start;
start = end;
end = life;
}
Style style = textPane.addStyle("MyHilite", null);
StyleConstants.setForeground(style, Color.GREEN.darker());
//style = textPane.getStyle("MyHilite");
doc.setCharacterAttributes(start, end - start, style, false);
}
정신 : 스타일은 JTextPane의 생성에 설정 될 수 있고, JTextPane의 필드로부터 검색된 프로그램 코드 outcommented 등.
지금까지 시도한 코드를 표시하십시오. – EnKrypt
'JTextPane' 또는'JEditorPane'이 당신에게 더 좋은 옵션이 될 수 있습니다. – berry120
감사합니다 베리 어떤 해결책이 있다면 jTextPane 또는 jEditorPane으로 변경할 수 있습니다. –