Click to See Complete Forum and Search --> : Jpanel and Borders


Giri
August 16th, 1999, 12:46 AM
If I have a JPanel with Titled Border with null Layout, and then if I add a component to the panel and do setBounds with x as 0
and y as 0, I am getting the component on the border it self how to get component inside the border by retaining the above
settings.
My email id is: girishakj@mailcity.com
Known guys please reply as early as possible.

RastaClown
August 16th, 1999, 12:52 PM
The reason that you are getting the component on the border is because of the way that Java uses absolute coordinates. It sets up the JPanel like any other component, where (0, 0) is the upper left coordinate. When it draws a border on the JPanel, it draws it ON the panel, using space that you want to lay out your own components. There are a couple of ways around this. First you can set up an offset system, by assinging your coordinates such as x = a + xOffset;
y = b + yOffset;

then you can assign xOffset and yOffset at a point with enough room to keep your compoenent out of the border, and then use a and b as constants to the relative position of where you want your component. In your example they would both be 0. The second way is to set up insets for the JPanel. I'm not positive if you can do this or not with a container, but it basically is like letting the computer handle buffered edges around the JPanel. You could then add the border and then set up the insets, and then add things at your coordinates and they would be offset away from the border.