Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:14:54+00:00 2026-06-13T08:14:54+00:00

When I create my GUI I use a cardlayout to hold my different panels

  • 0

When I create my GUI I use a cardlayout to hold my different panels as I’m sure many know. This sets my screen to the width and height of my largest panel. This causes problems with the aesthetics of my first to screens, which are much smaller than SudokuPanel and CalkuroPanel.

I have tried setting the preferred size when I change to the larger screens, but to no avail.

Any help with links to good info or anything that will just generally help would be greatly appreciated :).

Please find my main class (where I draw the GUI) below:

import java.awt.*; import javax.swing.*; import java.util.*;

public class puzzleGUI{
  private static JPanel screens;
  public static String username;
  static public void main (String[] args){
  JFrame puzzle = new JFrame ("Sudoku/Calkuro Pro");

  ...

  PuzzleStartPanel startPanel = new PuzzleStartPanel();
  PuzzleChoosePanel choosePanel = new PuzzleChoosePanel();
  PuzzleSudokuPanel sudokuPanel = new PuzzleSudokuPanel(); 
  PuzzleCalkuroPanel calkuroPanel = new PuzzleCalkuroPanel();

  screens = new JPanel(new CardLayout()); 
  screens.add(startPanel, "start");
  screens.add(choosePanel, "choosePuzzle");
  screens.add(sudokuPanel, "sudoku");
  screens.add(calkuroPanel, "calkuro");
  screens.setPreferredSize (new Dimension(250, 80));

  puzzle.setJMenuBar(menuBar);
  puzzle.getContentPane().add(screens);
  puzzle.pack();
  puzzle.setVisible(true);
  puzzle.setResizable(false);
  puzzle.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}

static public void getUsername(String str){
  username = str;
}

static public void openWindow(String newFrame){
  CardLayout cl = (CardLayout)(screens.getLayout());
  cl.show(screens, newFrame);
}
}

Edit

brainblast tried to pack the frame after resetting the preferred size when openWindow is called, and wolah, new frame size 😀

static public void openWindow(String newFrame, int a, int b){
  CardLayout cl = (CardLayout)(screens.getLayout());
  cl.show(screens, newFrame);
  screens.setPreferredSize (new Dimension(a, b));
  puzzle.pack();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:14:55+00:00Added an answer on June 13, 2026 at 8:14 am

    can i set the size of individual panels in a cardlayout

    Certainly. But the layout will ignore them and make every card the same size. The best you can hope for is to add the smaller panels to another panel (with a layout) that allows the content to shrink.


    This answer shows this technique using a single label. Swap the label for the ‘small panels’ and using the layouts on the right, it will be centered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you create a GUI element such as a JFrame like this new JFrame();
This is my first attempt to create a GUI in MATLAB. I haven't been
I use pyuic4 to create GUI and create a thread that do hard work,
i am trying to create a GUI only use native windows api. i create
I want to create a GUI in which the combo-box allows me to open
I'm trying to create a GUI Python app using Py2App, but am having trouble
I am trying to create a GUI using java swing. From there I have
I'm trying to create a GUI using Java by hand-coding it (without using GUI
So basically I want to create a GUI app using PySide and the Qt
I have an assignment to create a GUI using MATLAB GUIDE and am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.