Implementing absolute positioning for JPanels in java/netbeans JPanels applied through CardLayout!

I have a few JPanels stacked under a mainPanel via CardLayout under Netbeans 7.  Now for some weird reason I can't get any of these JPanels to maintain a setPreferredSize of [600,400] and most annoyingly I can't get the associated components to be placed right on where they're supposed to be positioned on their associated JPanel.  Please note that I'm using Netbeans 7 properties menu to set these parameters. I even have set up the minimum and maximum size parameters.
Who is Participating?
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.

You need to set a layout on the main panel that allows absolute positioning. As you probably know, the default is GroupLayout with the gui designer. It sounds like you attempted to do that, but perhaps have not done ...
snajalmAuthor Commented:
Done what??!

I already have the CardLayout in place with allows me to browse through my panels via "next" and "previous" buttons.  How can I have both these layouts be implemented so that I can get my "CardLayout" to impose absolute positioning on all it's underlying JPanels?!  
CardLayout is a special thing and doesn't affect in any way the layout of the components on any one 'card' you happen to be looking at. You need to set the correct layout on the main Container on the card
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Here's an example of a CardLayout with absolute positioning
import java.awt.*;
import java.awt.event.*;


import java.util.*;

import javax.swing.*;

public class FB extends JFrame implements ActionListener {
    private JButton b;
    private JPanel cards;
    private String[] CARD_NAMES = { "One", "Two", "Three" };
    private int currentCardIndex = 0;

    public void actionPerformed(java.awt.event.ActionEvent e) {
	CardLayout cLayout = (CardLayout)cards.getLayout();
	System.out.printf("Will now show card %d (%s)\n", currentCardIndex, CARD_NAMES[currentCardIndex]);, CARD_NAMES[currentCardIndex]);
	currentCardIndex %= CARD_NAMES.length;

    private void setGui() {
        try {
            setLocation(0, 100);

            Container cp = getContentPane();
	    cards = new JPanel();
	    cards.setLayout(new CardLayout());
	    cp.add(cards, BorderLayout.CENTER);
            JPanel bPanel = new JPanel();
            b = new JButton("Next");
            cp.add(bPanel, BorderLayout.SOUTH);
        } catch (Exception e) {

    private void addCards() {
        int x;
        int y;

        for (int i = 0; i < CARD_NAMES.length; i++) {
            x = y = (i * 30);

            String name = CARD_NAMES[i];
            JPanel p = new JPanel();

            JLabel lab = new JLabel(String.format("Card %s", name));
            lab.setBounds(x, y, 100, 25);
	    cards.add(p, name);

    public static void main(String[] args) {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        FB f = new FB();
                        f.setSize(200, 200);
        } catch (Exception e) {

Open in new window


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
snajalmAuthor Commented:
Thanks CEHJ!  I have implemented the CardLayout using Netbeans 7 which works fine, however, the mainPanel with the CardLayout layout does not maintain the preferredSize parametes.  I just don't understand why a JPanel's size can't be set to an unResizable state.  If there is a parameter that can set this up, please let me know since this thing is driving me crazy!  
snajalmAuthor Commented:
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

From novice to tech pro — start learning today.

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.