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 3395608
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:18:35+00:00 2026-05-18T04:18:35+00:00

At my JFrame I’d like to have a dashboard on the right and a

  • 0

At my JFrame I’d like to have a dashboard on the right and a custom canvas, where I will draw stuff on the left. The dashboard needs to be fixed width and canvas take the rest. So here is what I do in the JFrame constructor.

getContentPane().setLayout(new BorderLayout());
JPanel leftPanel = new JPanel();
JPanel rightPanel = new JPanel();
rightPanel.setLayout(new FlowLayout());
leftPanel.setLayout(new FlowLayout());
getContentPane().add(BorderLayout.EAST, rightPanel);
getContentPane().add(BorderLayout.CENTER, leftPanel);

rightPanel.add(new JLabel("Label1"));
rightPanel.add(new JLabel("Label2"));
rightPanel.setMaximumSize(new Dimension(100, 200));

leftPanel.add(new CustomCanvas());
pack();

As a result my canvas is squeezed to width 0.
What am I doing wrong?

  • 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-05-18T04:18:35+00:00Added an answer on May 18, 2026 at 4:18 am

    As a result my canvas is squeezed to width 0

    Unless you add a component to a panel it will have a default size of 0, as you have noticed. When you add it to the left panel which uses a FlowLayout it is displayed at its preferred size and the left panel is resized to fill the space in the Center of the BorderLayout.

    So the solution is to add your custom painting panel directly to the Center of the BorderLayout and get rid of the left panel.

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

Sidebar

Related Questions

I have created a JFrame with a canvas in it, like you can see
I have a JFrame which on instantiation calls a custom JDialog(Login). If login is
I have a JFrame which looks like a typical chat box. To connect and
I have a JFrame that displays a Java icon on the title bar (left
I currently have a JFrame where on it's content pane I draw images on
I have created a JFrame and I would like to associate a specific behaviour
I have a JFrame with a menu bar and a canvas covering all the
I have a JFrame with 1 panel for drawing and set KyeListener for JFrame.
I need my JFrame to have a squared size. In the beginning my frame
I have a simple JFrame with a JList, a JTable and two JButton as

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.