I want to use a JTextpane with fixed width but dynamic height which should also allow wrapping. The height should change as the user adds or removes text. I wou
Use a JScrollPane with no horizontal scroll.
JFrame frame = new JFrame();
JPanel pnel = new JPanel();
frame.setContentPane(pnel);
JTextPane txtpane = new JTextPane();
txtpane.setPreferredSize(new Dimension(200, 200));
JScrollPane jsp = new JScrollPane(txtpane,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
pnel.add(jsp);
frame.pack();
frame.setVisible(true);
This will not wrap text. To wrap text take a look at these: http://java-sl.com/wrap.html , http://java-sl.com/tip_html_letter_wrap.html
I will suggest to use JTextArea not JTextPane