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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:17:54+00:00 2026-06-06T02:17:54+00:00

I have to setup a basic JAVA application including a GUI based on swing.

  • 0

I have to setup a basic JAVA application including a GUI based on swing.
My idea was to create one JFrame and different JPanels and based on the users input to change the shown JPanel.
After running my application the JFrame is shown but not the content of the JPanel.
I thought up to here it should be strait forward… but as it seems it isn’t. Hope you can give me a hint 🙂

Here is my main:

public class Client {
    public static void main(String[] args) {
        MainWindow window = new MainWindow();
        window.setVisible(true);

        LoginView pane = new LoginView();
        window.getContentPane().add(pane);

        window.invalidate();
        window.repaint();
    }
}

my MainWindow:

package client;

public class MainWindow extends javax.swing.JFrame {
    public MainWindow() {
        initComponents();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void initComponents() {
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 352, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 250, Short.MAX_VALUE)
        );
        pack();
    }
}

my LoginView:

package client.views;

public class LoginView extends javax.swing.JPanel {
    public LoginView() {
        initComponents();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel1.setText("Login");
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addContainerGap(345, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addContainerGap(264, Short.MAX_VALUE))
        );
    }
    private javax.swing.JLabel jLabel1;
}
  • 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-06T02:17:56+00:00Added an answer on June 6, 2026 at 2:17 am

    You know the other thing, than calling revalidate() and repaint(), that I would do is instead of calling add() to the current content pane just set a new one.

    I think your issue is related to a incorrect way of adding component to the current content pane. I think this is the case here, therefore, use the setContentPane() method.

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

Sidebar

Related Questions

I have a basic nServicebus 3.2.0 setup with a web application endpoint and a
We have a Java web application and we'd like to set up some basic
I have a Swing application running on Java 1.6.0_20 on Windows XP (32-bit). I
I have setup the basic LAMP server on Ubuntu 11.10 and had a few
I have a basic invoice setup with models: Invoice, Item, LineItems. # invoice.rb class
Just a basic html link question. I have an intranet setup, and I need
I have basic Spring MVC 3 setup for i18n where I can show labels
I have a basic Socket.io server setup like this: var server = express.createServer().listen(port); this.io
I have a parent-child relationship setup that is fairly basic. The end result is
We're developing a data heavy modular web application stack with java but have little

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.