Reputation: 33082
I was having problems getting a null layout manager working, and I found this great page with things to remember when using a null layout manager. One of them was my issue, and I quickly moved on.
I'm now having similar problems with another panel using a null layout manager. However, I cannot find this page anywhere! So what are the things?
In the process of asking this question, I figured out my problem. I still want to add this knowledge to the site, since I couldn't find this question anywhere. It might be helpful to someone else.
To clarify, I already have determined that I need to use a null layout manager for this panel, due to dragging and animation requirements. That is not the question.
Upvotes: 2
Views: 174
Reputation: 324207
Adding a Component to a Container is something you do whether you use a null layout or a LayoutManager.
The 3 things that I believe you need to remember when using a null layout are:
set the size of the component (usually the preferred size)
set the location of the component
set the preferred size of the Container containing the components. Most time your code will work if you don't set the preferred size, but try adding the panel to a scroll pane and it won't work. The reason for this is that scrollbars appear automatically when the preferred size of the Container is greater than the size of the scrollpane. With a null layout the preferred size is 0.
Upvotes: 1
Reputation: 33082
I found the link I was looking for:
http://download.oracle.com/javase/tutorial/uiswing/layout/none.html
It gives these three things:
Container.setLayout(null)
.Component.setBounds()
for each of the container's children.Component.repaint()
As it happens, though, my problem was that I wasn't doing one additional thing:
Container.add(Component)
Upvotes: 1