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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:43:08+00:00 2026-05-28T13:43:08+00:00

I’m not a pro with swing layout managers and this behavior is completely baffling

  • 0

I’m not a pro with swing layout managers and this behavior is completely baffling me. Essentially I can’t add a JTextArea or JTextPane to my MigLayout without getting a NullPointerException.

I created a class that extends JPanel:

public ComponentPanel(TestComponent testComponent) {
    setLayout(new MigLayout("", "[]", "[][][][][][]"));

    JLabel lblNewLabel = new JLabel("New label");
    add(lblNewLabel, "cell 0 0");

    JButton button = new JButton("New button");
    add(button, "cell 0 3");

    JButton btnNewButton = new JButton("New button");
    add(btnNewButton, "cell 0 5");
}

This works fine. However, if I try adding a textArea, it will throw an exception when I try to build:

public ComponentPanel(TestComponent testComponent) {
    setLayout(new MigLayout("", "[grow]", "[][grow][][][][]"));

    JLabel lblNewLabel = new JLabel("New label");
    add(lblNewLabel, "cell 0 0");

    JTextArea textArea = new JTextArea();
    add(textArea, "cell 0 1,grow");

    JButton button = new JButton("New button");
    add(button, "cell 0 3");

    JButton btnNewButton = new JButton("New button");
    add(btnNewButton, "cell 0 5");
}

I’m using the Window Designer in eclipse, so I’m assuming something is horking up the MigLayout constructor? I’ve been beating my head on this for awhile and all I’ve managed to figure out is that adding textArea or textPanes causes the following exception:

java.lang.NullPointerException at
javax.swing.BoxLayout.preferredLayoutSize(Unknown Source) at
java.awt.Container.preferredSize(Unknown Source) at
java.awt.Container.getPreferredSize(Unknown Source) at
javax.swing.JComponent.getPreferredSize(Unknown Source) at
javax.swing.JRootPane$RootLayout.preferredLayoutSize(Unknown Source)
at java.awt.Container.preferredSize(Unknown Source) at
java.awt.Container.getPreferredSize(Unknown Source) at
javax.swing.JComponent.getPreferredSize(Unknown Source) at
java.awt.BorderLayout.preferredLayoutSize(Unknown Source) at
java.awt.Container.preferredSize(Unknown Source) at
java.awt.Container.getPreferredSize(Unknown Source) at
net.miginfocom.swing.MigLayout.adjustWindowSize(Unknown Source) at
net.miginfocom.swing.MigLayout.layoutContainer(Unknown Source) at
net.miginfocom.swing.MigLayout.preferredLayoutSize(Unknown Source) at
java.awt.Container.preferredSize(Unknown Source) at
java.awt.Container.getPreferredSize(Unknown Source) at
javax.swing.JComponent.getPreferredSize(Unknown Source) at
javax.swing.BoxLayout.checkRequests(Unknown Source) at
javax.swing.BoxLayout.layoutContainer(Unknown Source) at
java.awt.Container.layout(Unknown Source) at
java.awt.Container.doLayout(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validate(Unknown Source) at
java.awt.Window.show(Unknown Source) at
java.awt.Component.show(Unknown Source) at
java.awt.Component.setVisible(Unknown Source) at
java.awt.Window.setVisible(Unknown Source) at
com.soartech.ssim.testbed.gui.TestbedApplication$1.run(TestbedApplication.java:25)
at java.awt.event.InvocationEvent.dispatch(Unknown Source) at
java.awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.awt.EventQueue.access$000(Unknown Source) at
java.awt.EventQueue$1.run(Unknown Source) at
java.awt.EventQueue$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run(Unknown Source) Exception in thread
“AWT-EventQueue-0” java.lang.NullPointerException at
javax.swing.SizeRequirements.calculateTiledPositions(Unknown Source)
at javax.swing.BoxLayout.layoutContainer(Unknown Source) at
java.awt.Container.layout(Unknown Source) at
java.awt.Container.doLayout(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validateTree(Unknown Source) at
java.awt.Container.validate(Unknown Source) at
java.awt.Window.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.EventQueue.dispatchEventImpl(Unknown Source) at
java.awt.EventQueue.access$000(Unknown Source) at
java.awt.EventQueue$1.run(Unknown Source) at
java.awt.EventQueue$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue$2.run(Unknown Source) at
java.awt.EventQueue$2.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown
Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run(Unknown Source)

  • 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-28T13:43:09+00:00Added an answer on May 28, 2026 at 1:43 pm

    The problem ended up being that I needed to let SwingUtilities create my panels for me, because they were being programmatically generated.

        Runnable doWorkRunnable = new Runnable() {
            public void run() {
                for(TestComponent c : Config.getComponents()){
                    frame.getContentPane().add(new ComponentPanel(c));
                    frame.getContentPane().add(Box.createRigidArea(new Dimension(5,0)));
                }
            }
        };
    SwingUtilities.invokeLater(doWorkRunnable);
    

    Now that this is in place, I can include text areas in my MigLayout without any problems.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.