Karlovsky120
Karlovsky120

Reputation: 6352

JTextArea and display formatting issues

So, I have this text editing program, which is set up more as a form to be completed.

I'm unsure how to create the editor part of the program. On one hand, due to JTextArea, I'd be nice to have somekind(s) of layout(s) in order for it to expand and retract according the amount of text entered (word wrap enabled and all).

However, my document is composed out of series of questions (and several given answers). Number of rows in a question (JTextArea), and in answers (JTextArea) is variable, just like the number of given answers per question.

My editing area is composed out of column of pages (which would be added and removed as needed), and I somehow have to detect when a certain question goes out of bounds of a page (or its margins, to be precise).

So in the end, I'd need some kind of semi-rigid layout manager. On one hand to make JTextAreas resizable with setPreferredSize, and on the other hand, that situation when page gets filled up to a point where adding anything else ruins aestetic look of the page is detected and program moves onto the next page.

One thing to keep in mind is that I intend to make possible for user to add/remove whole questions and some answers within the document, not necessarily on the very end.

(the whole thing is used only to present the document to the user (and make it editable), it is later to be exported as a pdf, but that's a whole another story)

I don't even have to use JTextAreas (if you have something better), you can suggest anykind of external java library, I just want to get it to work...

Upvotes: 2

Views: 342

Answers (1)

StanislavL
StanislavL

Reputation: 57381

You can detect height to show some content of JEditorPane with fixed width http://java-sl.com/tip_text_height_measuring.html

So add your content step by step measuring whether allowed height is achieved. When achieved create a new page.

Alternatively you can add all your content in JEditorPane with pagination (described here http://java-sl.com/articles.html)

Upvotes: 2

Related Questions