I have a GUI setup that looks like this:
It displays a document and enables user to edit it by adding/removing JTextAreas
and text in them.
I have a problem when trying to open the document. Document itself is made up of layers of JPanels
on top of each other. There are never more than 6 layers of JPanels
at a single point in the GUI.
Since I don't know what the height of the JTextArea
will be, I have to make it relative to the parent (in other words, not specify it).
Because the layout manager (MigLayout
) doesn't know the exact size of the component (it's relative to the parent), it first asks its parent for the parent's size. That size is again unknown and the parent's parent is asked and so on (until a level 1 or 2 JPanel). In the end it has to ask a lot of components for their size (a method checkParent(Container)
within MigLayout was called over 100 000 times just for the example above).
What I need to do is set the height of the JTextArea
(or the JPanel
that it resides in) only when the document is being opened, so the layout manager doesn't have to ask JTextAreas
parent, causing a recursive hell.
After the document is opened I have to reset the height to default (so the height adjusts when the text is added/removed).
I have absolutley no idea how to do this, or if this is the way to go, I'm only sure that the thing I described above is the problem.
Several notes:
- this is not a
MigLayout
bug, I have been to the forums(link below) - check this out (the last post)
- I can't put a
JScrollPane
into theJTextArea
as its task isn't only to hold the information, but to display exactly how much room it takes - I can easily get the heights of the
JTextAreas
when saving the document, thus having them at my disposal when opening it again
EDIT: The document referenced in this question is not "the document" as thingy used in JTextAreas and similar, but "a document" as in custom class in my program (which I didn't mention because it is irrelevant, unless it's understood as "the document").