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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:55:29+00:00 2026-05-24T18:55:29+00:00

I’m really stuck with a layout I have to make with java swing. I

  • 0

I’m really stuck with a layout I have to make with java swing.

I have to build a dynamic form, while iterating through a vector of labels and input components.

Here is how it should:

enter image description here

In this image, you can see, what should be the result. Between the green lines is one pair of label/input component. I also get a constraint, telling me, if I have to lay them out in one row 50/50 or in two rows or in one row 25/75 or 75/25. Also the whole form must be resizable with the 50/50, 25/75 and 75/25 ratio still correct.

I tried GridBagLayout which worked quite nice, but as you can see in the first row in the picture, the label can be very long. So I used a JTextarea but GridBagLayout cut it off. I also treid JGoodies FormLayout, but also had trouble with the Textarea for long labels.

The 25/75 and 75/25 ratio is not that important, but actually it is also part of what I have to do.

I think it is just really difficult to make a Textarea expand its parent component.

I also read/wrote these aricles:

  • How can I create a JTextArea with a specified width and the smallest possible height required to display all the text?
  • How to implement dynamic GUI in swing
  • Expand JList row height depending on content

but I’m still stuck.

Does any one of you has any idea on how to accomplish this?

Thanks

  • 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-24T18:55:30+00:00Added an answer on May 24, 2026 at 6:55 pm

    It’s been a while since I’ve done much Swing, but two thoughts:

    1. If a control is being cut off, that sounds like you’re not setting the minimum size.

    2. I don’t think any of the off-the-shelf layout managers have a feature to maintain a ratio of sizes like your 25/75 split. But don’t despair! You can write your own layout manager. Back when I was doing a lot of Swinging I wrote several layout manager. (I would say, “for specialized requirements”, but really they were for quite general requirements, and it always surprised me that Java didn’t include canned layout managers to handle such things. Like: you often want a row or column of buttons where all the buttons are the same size, so you have to find what button has the longest text, and then resize all the others to match it. Or: set up rows and columns where each colum is sized to the widest thing in that column, but the width of one column has no effect on other columns; then similarly for rows.) Anyway, what you’re describing IS fairly unusual, so you may just want to write your own layout manager.

    The trick to writing a layout manager is just to implement a few key functions: (a) Calculate the X and Y co-ordinates where you’ll place each control given the overall size; (b) Calculate the minimum size required; (c) Calculate the preferred size; (d) Calculate the maximum size you’ll use. Umm, there may be one or two more I’m forgetting, but it’s not that big a deal. When I first thought about “writing my own layout manager” that sounded to me like “write your own database engine” or “write your own compiler” at first, but it’s not really anywhere near that scary. It’s typically a few hundred lines of code.

    Of course if someone else on here can tell you how to do what you want to do with one of the canned layout managers, that’s surely a lot easier.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
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 a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.