यह एक उदाहरण है जो ऊंचाई दृश्य भाग केवल की चौड़ाई प्रिंट,
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
public class TestWidth {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextPane newsTextPane = new JTextPane();
newsTextPane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(newsTextPane);
frame.add(scrollPane);
frame.setSize(300, 250);
frame.setVisible(true);
System.out.println("Height : " + scrollPane.getViewport().getSize().height + "\nWidth :" + scrollPane.getViewport().getSize().width);
}
}
दुर्भाग्य है, मैं इस वर्ग के 'कोड को बदल नहीं सकते, मैं सिर्फ इसके साथ काम कर सकते हैं। – Flot2011
आपको किसी भी कक्षा 'कोड की आवश्यकता नहीं है, आपको केवल JViewport निकालने और इसके साथ काम करने की आवश्यकता है – mKorbel