Reputation: 6352
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:
MigLayout
bug, I have been to the forums(link below)JScrollPane
into the JTextArea
as its task isn't only to hold the information, but to display exactly how much room it takesJTextAreas
when saving the document, thus having them at my disposal when opening it againEDIT: 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").
Upvotes: 0
Views: 97
Reputation: 205795
Because your Document
models a hierarchical structure, you need a tree. Because your interface requires both a control and a view for each node, you need a table. Outline
, seen here, might be a suitable choice. Your DocumentTreeModel
would hold a reference to the document's root Element
, just as the example's FileTreeModel
holds a reference to the root File
. Your RowModel
would include a JLabel
, a JCheckBox
and a JTextArea
.
Upvotes: 1