What method do I have to invoke so as to show only 20 chars of the JTextPane
A JTextPane
doesn't support this concept.
If you are only displaying simple text (and don't need multiple fonts or text color) then you can use a JTextArea
. Then you would do something like:
JTextArea textArea = new JTextArea(5, 20);
JScrollPane scrollPane = new JScrollPane(textArea);
This will create a text area that contains 5 rows and 20 columns. The columns is not exact because the width of every character is different. If you want exactly 20 characters then you would need to use a monospaced font.