मैं एक JTextPane रखना चाहता हूं जिसमें स्क्रॉल बार है, मैं ऐसा कैसे कर सकता हूं? धन्यवाद।स्क्रॉल करने योग्य JTextPane कैसे करें?
13
A
उत्तर
17
अपने नए JTextPane पर एक स्क्रॉल पट्टी सम्मिलित करने के लिए, बस का उपयोग एक jScrollPane:
JTextPane txt = new JTextPane();
JScrollPane jsp = new JScrollPane(txt);
JTextPane एपीआई: http://download.oracle.com/javase/6/docs/api/javax/swing/JTextPane.html
jScrollPane एपीआई: http://download.oracle.com/javase/6/docs/api/javax/swing/JScrollPane.html
आप कुछ समस्या है तो , इस SO प्रश्न पर एक नज़र डालें: Java JTextPane JScrollPane Display Issue
या पर एक नज़र डालें: http://www.daniweb.com/software-development/java/threads/30283
5
इसे जेएसक्रॉलपैन में लपेटें। swing tutorial about scroll panes पढ़ें।
2
बस जेएसक्स्टपेन को जेएसक्रॉलपेन में रखें।
public class SomeFrame
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextPane tp = new JTextPane();
JScrollPane sp = new JScrollPane(tp);
frame.getContentPane().add(sp);
frame.pack();
frame.setVisible(true);
}
}
0
इस से पहले सिर्फ डिजाइन में contentPane करने के लिए एक Scrollpane जोड़ सकते हैं और बच्चे
JScrollPane sp = (JScrollPane)contentPane.getComponent(23);//this is in my hierarchy 23
JViewport vp = sp.getViewport();
JEditorPane ep = (JEditorPane)vp.getView();
0
यहाँ के रूप में Scrollpane को EditopPane जोड़ने पाठ बॉक्स
करने के लिए एक स्क्रॉलबार जोड़ने के लिए कोड हैJEditorPane edtDTWinfo = new JEditorPane();
edtDTWinfo.setEditable(false);
edtDTWinfo.setBorder(new LineBorder(Color.ORANGE, 2));
edtDTWinfo.setForeground(Color.BLUE);
JScrollPane spEditor = new JScrollPane(edtDTWinfo,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
spEditor.setBounds(0, 0, 200, 300);
जोड़ें घटक "spEditor" JPanel
को