Based on existing solutions, I haven't found a way to make a JTextPane (or JEditorPane) have either word-wrap or forced line-wrap inside a JScrollPane. JTextArea is not a solution as I need HTML to display in the particular input.
output = new JTextPane();
scrollPane.setViewportView(output);
contentPane.add(scrollPane, gbc_scrollPane);
output.setEditorKit(new WrapEditorKit());
output.setForeground(Color.WHITE);
output.setFont(new Font("Courier New", Font.PLAIN, 12));
output.setEditable(false);
output.setContentType("text/html; charset=UTF-8");
output.setBackground(Color.DARK_GRAY);
The WrapEditorKit is the one available here. I have also tried ScrollablePanel, but every time the JTextPane's text is not wrapped at all. How would one go around to implement a JTextPane inside a JScrollPane with only vertical scrolling (and horizontal word or forced line wrap)?
It is apparently caused by the <pre>
tags rather than any other setting. Without the <pre>
tags, the text seems to wrap properly. I originally added them to prevent an another issue with newlines, but I'll try to fix it using some other method then. This could've never have happened with some more advanced HTML skills.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With