एक 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("Java
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.
");
setSize(350, 275);
setContentPane(editorPane);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String[] a) {
new JEditorPaneTest();
}
}
आउटपुट
