Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextPane + JScrollPane + word wrap?

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)?

like image 249
CosmoConsole Avatar asked Nov 10 '22 21:11

CosmoConsole


1 Answers

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.

like image 101
CosmoConsole Avatar answered Nov 14 '22 23:11

CosmoConsole