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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:58:56+00:00 2026-06-18T04:58:56+00:00

I am writing a program that brings up a JDialog box that lists multiple

  • 0

I am writing a program that brings up a JDialog box that lists multiple options from a config file. The number of options can vary each time it is opened, so I need to be able to dynamically adjust the height of the window, but not the width. The window looks best using FlowLayout and defining the width of the window so that the JPanels that the data is in wrap propertly. But I am unable to dynamically adjust the height. I tried to use the pack method, but it lines all the panels up in one line like FlowLayout is meant to be. I tried GridLayout but it re-sizes all of the panels to the same size and is an unacceptable look. I also tried BoxLayout but was unable to get that one to work.

Is there a better layout manager to use or a way to make the width static?

Here is my code. Every panel and box is defined above the constructor, I just did not copy that code:

public ReSizeMe()
    {
        curConfig = new Config();
        config = curConfig.getConfig();

        setBox = new JDialog();

        setBox.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);  //  Set as 480, 600
        setBox.setLayout(new FlowLayout());

        this.buildSetFrame();

        //setBox.pack();
        setBox.setVisible(true);
    }

    public void buildSetFrame()
    {
        intPanel   = new JPanel();
        butPanel   = new JPanel();
        optPanel   = new JPanel();
        editPanel  = new JPanel[maxOptions];
        optWrapper = new JPanel[maxOptions];

        intPanel.setLayout(new FlowLayout());
        optPanel.setLayout(new GridLayout(10, 1));   //  trying different things here too.

        optText = new JTextField[maxOptions];
        editButton = new JButton[maxOptions];
        delButton = new JButton[maxOptions];

        intPanel.setBorder(BorderFactory.createTitledBorder("Modify Interface"));

        apply  = new JButton("Apply");
        newOpt = new JButton("New Option");
        help   = new JButton("Help");
        close  = new JButton("Close");

        intPanel.add(ethIntLabel);
        intPanel.add(ethIntName);

        butPanel.add(apply);
        butPanel.add(newOpt);
        butPanel.add(close);

        ethIntName.setText(config.getProperty("EthIntName"));

        setBox.add(welcomeMsg);
        setBox.add(intPanel);
        setBox.add(optPanel);

        buildOptions();

        setBox.add(butPanel);
    }

    void buildOptions()
    {
        for (int i = 0; i < maxOptions; i++)
        {
            editable = Boolean.parseBoolean(config.getProperty("option." + i + ".edit"));

            if (config.getProperty("option." + i + ".name") == null)
            {
                break;
            }
            else if (editable != false && 
                     config.getProperty("option." + i + ".name") != null && 
                     !config.getProperty("option." + i + ".name").isEmpty())
            {

                editPanel[i]  = new JPanel();
                optWrapper[i] = new JPanel();
                optText[i]    = new JTextField(20);
                editButton[i] = new JButton("Edit");
                delButton[i]  = new JButton("Delete");

                editButton[i].setActionCommand(Integer.toString(i));
                delButton[i].setActionCommand(Integer.toString(i));

                optText[i].setText(config.getProperty("option." + i + ".name"));
                optText[i].setEditable(false);
                editPanel[i].add(editButton[i]);
                editPanel[i].add(delButton[i]);
                optWrapper[i].add(optText[i]);
                optWrapper[i].add(editPanel[i]);
                optPanel.add(optWrapper[i]);
            }
        } 
    }
  • 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-18T04:58:57+00:00Added an answer on June 18, 2026 at 4:58 am

    Yes, Box should work wonderful:

    Box box = Box.createVerticalBox();
    box.add(...)
    box.add(Box.createVerticalStrut(5)); // spacing
    <etc.>
    
    add(box);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a program that should read data from an online XML file. The
I am writing a program that takes in an input file from the user.
I'm writing a program that will guess words taken from a big text file.
I'm writing a program that needs to watch for file system events on multiple
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting
I am writing a program that sets up a file path that I use
I'm writing a program that, summarized, takes a notepad file and saves it as
I am writing a program that grabs analog and discrete data points from a
Currently I'm writing a program that can estimate the costs of an Azure application.

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.