NetBeans: stacking controls

Hello,

How can I stack one control on top of another? NetBeans keeps moving the controls when I try to stack them...

How do I get NetBeans to stop moving the controls when I try to stack them?

Thanks,
Ryan
rossryanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sailingbyeCommented:
Do you want the controls to be exactly stacked, i.e. not overlapped?
If so, then the java.awt.CardLayout may be what you need.

Create an appropriate container for your controls (panel, frame, etc.), give it a CardLayout to manage the controls and then add your controls to the container.  

Extract from API :

"[CardLayout] treats each component in the container as a card. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to a CardLayout object is the visible component when the container is first displayed ... "

Hope this helps.
0
rossryanAuthor Commented:
Nulllayout is what I needed to change it to. Any more information on these different types of layouts?

Thanks,
Ryan
0
sailingbyeCommented:
Hi

Setting the layout manager to null is a way of saying, "I want to have manual control of the layout of this component". It is appropriate to do this when
 * none of the layout managers provided by the API provide the required functionality, and
 * you cannot justify creating your own layout manager (by sub-classing an existing one for example).

In my experience, the layout managers provided by the API cover the vast majority of user-interface behaviours and manual layout leads to unorthodox user-interfaces which, for this reason, are not user-friendly.

Another great advantage of using a layout manager is reduced coding effort. Why re-invent the wheel?  For example, the CardLayout manager provides next, previous and show methods for navigating components/controls. Other layout managers provide methods appropriate to their functionality.

Perhaps, if you describe your requirements in a little more detail I can help you select an appropriate layout manager (or agree that null/manual is the way to go)?
// Get the layout manager for this component
CardLayout layoutManager = (CardLayout)(this.getLayout());

// ...

// Flip to the next component in the 'stack' of components
layoutManager.next(this);

// ...

// Show a specific component (named "preferences") in the 'stack'
layoutManager.show(this, "preferences");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.