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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:03:06+00:00 2026-06-14T19:03:06+00:00

Not sure why this error is coming up. I am using GroupLayout because I

  • 0

Not sure why this error is coming up. I am using GroupLayout because I want it to do the spacing for me and will be adding more panels to the frame in the future. Below is the stack trace.

Exception in thread "main" java.lang.IllegalArgumentException: GroupLayout can only be used with one Container at a time
    at javax.swing.GroupLayout.checkParent(Unknown Source)
    at javax.swing.GroupLayout.invalidateLayout(Unknown Source)
    at java.awt.Container.invalidate(Unknown Source)
    at java.awt.Component.addNotify(Unknown Source)
    at java.awt.Container.addNotify(Unknown Source)
    at javax.swing.JComponent.addNotify(Unknown Source)
    at java.awt.Container.addNotify(Unknown Source)
    at javax.swing.JComponent.addNotify(Unknown Source)
    at java.awt.Container.addNotify(Unknown Source)
    at javax.swing.JComponent.addNotify(Unknown Source)
    at javax.swing.JRootPane.addNotify(Unknown Source)
    at java.awt.Container.addNotify(Unknown Source)
    at java.awt.Window.addNotify(Unknown Source)
    at java.awt.Frame.addNotify(Unknown Source)
    at java.awt.Window.pack(Unknown Source)
    at client.AlternateGUI.drawGui(AlternateGUI.java:54)
    at client.AlternateGUI.main(AlternateGUI.java:24)

Here is the code:

package client;

import java.awt.Component;*

public class AlternateGUI {
    private JList people;
    private DefaultListModel dlm;
    private JLabel l1, l2, l3;
    private JFrame alternateGUIFrame;
    private final static ImageIcon unavailableIcon = new ImageIcon("offline.png");

    public static void main(String[] args)
    {
        AlternateGUI ls = new AlternateGUI();
        ls.drawGui();
    }

    public AlternateGUI(){
        dlm = new DefaultListModel();
        people = new JList(dlm);

        alternateGUIFrame = new JFrame();

        JScrollPane peopleScroller = new JScrollPane(people, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        people.setCellRenderer(new CellRenderer());

        GroupLayout alternateGUILayout = new GroupLayout(alternateGUIFrame);
        alternateGUIFrame.setLayout(alternateGUILayout);

        alternateGUILayout.setAutoCreateGaps(true);
        alternateGUILayout.setAutoCreateContainerGaps(true);
        alternateGUILayout.setHorizontalGroup(alternateGUILayout.createSequentialGroup()
                .addComponent(peopleScroller));
        alternateGUILayout.setVerticalGroup(alternateGUILayout.createSequentialGroup()
                .addComponent(peopleScroller));
        }

    public void drawGui() {
        l1 = new JLabel("Hi", unavailableIcon , JLabel.LEFT);
        l2 = new JLabel("Hello", unavailableIcon , JLabel.LEFT);
        l3 = new JLabel("Bye", unavailableIcon , JLabel.LEFT);
        dlm.addElement(l1);
        dlm.addElement(l2);
        dlm.addElement(l3);

        alternateGUIFrame.pack();
        alternateGUIFrame.setVisible(true);
    }

    class CellRenderer implements ListCellRenderer
    {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
        {
            Component com = (Component)value;
            return com;
        }
    }
}
  • 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-14T19:03:09+00:00Added an answer on June 14, 2026 at 7:03 pm

    Your problem is that you’re unknowingly adding the layout to both the JFrame and its contentPane. The solution is to make sure you add it to the JFrame’s contentPane only:

      GroupLayout alternateGUILayout = new GroupLayout(alternateGUIFrame.getContentPane());
      alternateGUIFrame.getContentPane().setLayout(alternateGUILayout);
    

    It’s the first line above that matters the most.

    Another option is to work with JPanels, and then add the JPanels to the JFrame’s contentPane in its default BorderLayout.CENTER position.

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

Sidebar

Related Questions

I am not sure what this error is. Thought I would ask you guys
Hey, not 100% sure what this error means. % for f in * ;
Not sure why I'm getting this error and can't figure it out? The cycle
Hello not sure why Im getting this error. Basically I get it in these
I am not sure why I get this error: Caused by: java.lang.RuntimeException: Deferred binding
I'm completely lost on this, I'm not sure what is causing this error: Fatal
I got this error message and I'm not quite sure whats wrong: Exception in
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8
I'm not sure why this isn't working. I don't have any errors, but what
Not sure this is possible, but looking to write a script that would return

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.