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

  • Home
  • SEARCH
  • 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 3440862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:28:59+00:00 2026-05-18T08:28:59+00:00

My Code: public MyConstructor() { view = new JPanel(new GridLayout(3, 1)); header = new

  • 0

My Code:

public MyConstructor() {
    view = new JPanel(new GridLayout(3, 1));
    header = new JPanel(new GridLayout(2, 1));//2 ROWS 1 COLUMN
    foot = new JLabel("Copyright...");
    content = new JPanel();
    info = new JLabel("");
    logo = new JLabel() {

        BufferedImage img;

        @Override
        public void paint(Graphics g) {
            try {
                img = ImageIO.read(new File("logo.jpg"));
            } catch (IOException e) {
            }
            g.drawImage(img, 0, 0, null);
        }
    };
    window.add(view);
    header.add(logo);
    header.add(info);
    view.add(header);
    view.add(content);
    view.add(foot);
    window.setLocation(width / 2, 100);
   window.setSize(width, height);
    window.setPreferredSize(new Dimension(width, height));
    content.setSize(window.getWidth(), height-70);
    content.setPreferredSize(new Dimension(window.getWidth(), height-70));
}

“window” is the frame…the class is not extending JFrame
My class is going to be a super class to others, the subclasses inherit the public content JPanel. In my super class i’m trying to set the width and height of the 3 sections of my GridLayout, the logo and info components add up to 70 for their height…I’ve set the other components (view,header,info,logo) private so that subclasses can’t access them…

When the application runs a window is shown for the login, this displays and resizes properly. once logged in an instance of one of the subclasses is created, the login window is then hidden site setVisible(false)

when the new window is shown however, the JFrame is the correct size but the header,content and footer are not the currect sizes.
I’ve tried setting the size and preferred size each of the components but still not working…I’ve also tried calling repaint and validate/revalidate

Any ideas?

  • 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-18T08:29:00+00:00Added an answer on May 18, 2026 at 8:29 am

    It sounds like your design could be improved. Why do these variables need to be attributes of a superclass? Why not just have a method that constructs the panels that you need and a constructor that adds them so that you get fresh panels for each instance?

    In fact, why not just create the header and footer classes and reuse them instead of having to subclass a frame just to get the same header and footer?

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

Sidebar

Related Questions

here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
The following code public class GenericsTest2 { public static void main(String[] args) throws Exception
I have the following code: public static T ParameterFetchValue<T>(string parameterKey) { Parameter result =
I have the following code: public class Test { public static void Main() {
I have a simple piece of code: public string GenerateRandomString() { string randomString =
take a look at this example code: public class Comment { private Comment() {
Let's say I have some Java code: public class SomeClass { static { private
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
I'm struggling to separate the dependencies in the following code: public static SiteConnector ConnectToSite(String
I'm trying to compile a POCO with this code public class MenuItem { public

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.