Reputation: 10285
I have a JPanel panel which contains a JTree tree. Sometimes the JTree has width or height greater then the panel itself.
What I want to do is recalculate the height and width of tree using the height and width of panel. The only problem is that I don't know how to get the margins introduced by a JPanel in order to precisely calculate the new Size of the JTree.
Example of what i want:
if (treeHeight >= panelSize.getHeight()) {
treeHeight = panelSize.getHeight() - panelMargins; // panelMargins is what I don't know how to calculate
}
UPDATE :
Upvotes: 1
Views: 110
Reputation: 109813
you have to use
1) proper LayoutManager
2) add EmptyBorder
then you never need that
Upvotes: 5