JTextPane JEditorPane 의 확장입니다. 글꼴, 텍스트 스타일, 색상과 같은 워드 프로세싱 기능을 제공합니다. 등. 강력한 텍스트 처리를 수행해야 하는 경우 이 클래스를 사용할 수 있지만 JEditorPane HTML 표시/편집 지원 및 RTF 콘텐츠 자체 EditorKit을 만들어 확장할 수 있습니다. .
JTextPane
- JTextPane JEditorPane의 하위 클래스입니다. .
- JTextPane 포함된 스타일이 지정된 문서에 사용됩니다. 이미지 및 구성 요소.
- JTextPane 그래픽으로 표시되는 속성으로 마크업할 수 있는 텍스트 구성요소이며 DefaultStyledDocument 를 사용할 수 있습니다. 기본 모델로 사용합니다.
- JTextPane의 중요한 메소드는 addStyle(), getCharacterAttributes(), getStyledDocument(), setDocument(), setEditorKit(), setStyledDocument() 등
예시
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class JTextPaneTest {
public static void main(String args[]) throws BadLocationException {
JFrame frame = new JFrame("JTextPane Test");
Container cp = frame.getContentPane();
JTextPane pane = new JTextPane();
SimpleAttributeSet set = new SimpleAttributeSet();
StyleConstants.setBold(set, true);
pane.setCharacterAttributes(set, true);
pane.setText("Welcome to");
set = new SimpleAttributeSet();
StyleConstants.setItalic(set, true);
StyleConstants.setForeground(set, Color.blue);
Document doc = pane.getStyledDocument();
doc.insertString(doc.getLength(), " Tutorials ", set);
set = new SimpleAttributeSet();
StyleConstants.setFontSize(set, 20);
doc.insertString(doc.getLength(), " Point", set);
JScrollPane scrollPane = new JScrollPane(pane);
cp.add(scrollPane, BorderLayout.CENTER);
frame.setSize(375, 250);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
} 출력

JEditorPane
- JEditorPane 다양한 텍스트 형식을 표시할 수 있는 일종의 텍스트 영역입니다.
- 기본적으로 JEditorPane HTML 지원 및 RTF(서식 있는 텍스트 형식) , 특정 콘텐츠 유형을 처리하는 자체 편집기 키트를 구축할 수 있습니다.
- setContentType()을 사용할 수 있습니다. 표시할 문서를 선택하는 메소드와 setEditorKit() JEditorPane 에 대한 사용자 정의 편집기를 설정하는 방법 명시적으로.
예시
import javax.swing.*;
public class JEditorPaneTest extends JFrame {
public JEditorPaneTest() {
setTitle("JEditorPane Test");
JEditorPane editorPane = new JEditorPane();
editorPane.setContentType("text/html");
editorPane.setText("<h1>Java</h1><p>is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.</p>");
setSize(350, 275);
setContentPane(editorPane);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] a) {
new JEditorPaneTest();
}
} 출력
