Adel Boutros
Adel Boutros

Reputation: 10285

How do you get the margins introduced by a JPanel

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 :

  1. My JTree is already in a JScrollPane
  2. My JScrollPane is inside the Jpanel

Upvotes: 1

Views: 110

Answers (1)

mKorbel
mKorbel

Reputation: 109813

you have to use

1) proper LayoutManager

2) add EmptyBorder

then you never need that

Upvotes: 5

Related Questions