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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.