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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:23:06+00:00 2026-05-26T07:23:06+00:00

I have a border layout, and a JPanel on the right. The JPanel has

  • 0

I have a border layout, and a JPanel on the right. The JPanel has absolute layout, and it doesn’t contain anything because I’m using it to draw graphics (overriding paintComponent(Graphics g))

The problem is that the panel doesn’t show (it’s there but like 1 pixel wide). I tried to setSize on the panel.. but that doesn’t work..

How do I do it?

frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
JPanel panelCenter = new JPanel();
panelRight = new ActorDrawer();
frame.getContentPane().add(panelRight, BorderLayout.EAST);
panelRight.setSize(200, 400);
panelRight.setLayout(null);
frame.getContentPane().add(panelCenter, BorderLayout.CENTER);
frame.getContentPane().add(panelBottom, BorderLayout.SOUTH);
table = new JTable(new MyTableModel());
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
panelCenter.add(scrollPane);
  • 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-26T07:23:06+00:00Added an answer on May 26, 2026 at 7:23 am

    Look into the JPanel.setPreferredSize() method. Also, I think the JFrame.setBounds() call is not what you are looking for. Here’s an example:

    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    
    public class Sandbox extends JFrame
    {
        class MyPanel extends JPanel
        {
            public void paintComponent(Graphics g)
            {
                g.setColor(Color.RED);
                g.fillRect(0, 0, this.getWidth(), this.getHeight());
            }
        }
    
        public static void main(String[] args)
        {
            Sandbox s = new Sandbox();
        }
    
        public Sandbox()
        {
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLayout(new BorderLayout());
    
            MyPanel panelRight = new MyPanel();
            panelRight.setPreferredSize(new Dimension(150, 300));
            this.getContentPane().add(panelRight, BorderLayout.EAST);
    
            JPanel panelCenter = new JPanel();
            this.getContentPane().add(panelCenter, BorderLayout.CENTER);
    
            JScrollPane scrollPane = new JScrollPane(new JTable());
            panelCenter.add(scrollPane);
    
            JPanel panelBottom = new JPanel();
            this.getContentPane().add(panelBottom, BorderLayout.SOUTH);
    
            this.setSize(400, 400);
            this.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPanel inside BorderLayout.CENTER The JPanel has a Grid Layout, and I
I have a border layout whose center panel is defined like the below. {
I have a border layout in ExtJS, The north region contains some HTML, but
I have a JFrame with BorderLayout as the layout manager. In the south border,
We have a JPanel which contains multiple JPanels which contain JComponents (let's say JLabels
I have a problem making an inner class that extends from JPanel to draw
I just can't get this right. I have a slider to increase my JPanel's
I have a border layout with 4 panels, north, south, east and west. For
So I have a JFrame , in which it has a bunch of JPanel
I have a border element with rounded corners containing a 3x3 grid. The corners

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.