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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:39:18+00:00 2026-06-18T01:39:18+00:00

Here’s what I actually want to put on a panel: First logical block: radio

  • 0

Here’s what I actually want to put on a panel:

First logical block:

radio button 1       text field     icon button

radio button 2       text field     icon button

check box

Second logical block:

Label       Spinner

        Button

My first decision is to make Vertical Box Layout and put there two Horizontal Box Layouts – for each logical block. But the problem is with these blocks, what layouts to choose to describe this structure? I dislike GridBagLayout – it is very composite and difficult to understand, especially when code isn’t yours. For the moment I see that Flow Layout and Grid Layout can be used. But Grid Layout, for example, stretches buttons to the width of a cell and if a button is with icon only it, it looks very strange then.

Hope you can advise me something.

  • 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-18T01:39:19+00:00Added an answer on June 18, 2026 at 1:39 am

    For the first case you can use a simple GridLayout on the JPanel with 3 Rows each having a separate JPanel with FlowLayout having constraints, FLowLayout.LEFT. Have a look at this code example :

    import java.awt.*;
    import javax.swing.*;
    
    public class ExampleLayout
    {
        private void displayGUI()
        {
            JFrame frame = new JFrame("Example Layout");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
            JPanel contentPane = new JPanel();
            contentPane.setLayout(new GridLayout(0, 1, 5, 5));
    
            JPanel topPanel = new JPanel();
            topPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    
            JRadioButton rbut1 = new JRadioButton("RadioButton 1", false);
            JTextField tfield1 = new JTextField(10);
            JButton button1 = new JButton("Button 1");
    
            topPanel.add(rbut1);
            topPanel.add(tfield1);
            topPanel.add(button1);
    
            JPanel middlePanel = new JPanel();
            middlePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    
            JRadioButton rbut2 = new JRadioButton("RadioButton 2", false);
            JTextField tfield2 = new JTextField(10);
            JButton button2 = new JButton("Button 2");
    
            middlePanel.add(rbut2);
            middlePanel.add(tfield2);
            middlePanel.add(button2);
    
            JPanel bottomPanel = new JPanel();
            bottomPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
            JCheckBox cbox = new JCheckBox("CheckBox 1", false);
            bottomPanel.add(cbox);
    
            contentPane.add(topPanel);
            contentPane.add(middlePanel);
            contentPane.add(bottomPanel);
    
            frame.setContentPane(contentPane);
            frame.pack();
            frame.setLocationByPlatform(true);
            frame.setVisible(true);
        }
    
        public static void main(String... args)
        {
            EventQueue.invokeLater(new Runnable()
            {
                @Override
                public void run()
                {
                    new ExampleLayout().displayGUI();
                }
            });
        }
    }
    

    OUTPUT :

    FIRST BLOCK

    And for the Second case, simply add first two components to the JPanel having default Layout. And for the third components, simply add components on to a JPanel having GridBagLayout, with no constraints.

    EDIT #1 :

    Or you can use this approach, for your second block.

    import java.awt.*;
    import javax.swing.*;
    
    public class ExampleLayout
    {
        private void displayGUI()
        {
            JFrame frame = new JFrame("Example Layout");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
            JPanel contentPane = new JPanel();
            contentPane.setLayout(new BorderLayout(5, 5));
    
            JPanel basePanel = new JPanel();
            basePanel.setLayout(new GridLayout(0, 1, 5, 5));
    
            JPanel topPanel = new JPanel();
            //topPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    
            JLabel label1 = new JLabel("Label 1", JLabel.CENTER);
            JRadioButton rbut1 = new JRadioButton("RadioButton 1", false);
    
            topPanel.add(label1);
            topPanel.add(rbut1);        
    
            JPanel middlePanel = new JPanel();
            middlePanel.setLayout(new GridBagLayout());
    
            JButton button1 = new JButton("Button 1");
    
            middlePanel.add(button1);
    
            basePanel.add(topPanel);
            basePanel.add(middlePanel);
    
            contentPane.add(basePanel, BorderLayout.PAGE_START);
    
            frame.setContentPane(contentPane);
            frame.pack();
            frame.setLocationByPlatform(true);
            frame.setVisible(true);
        }
    
        public static void main(String... args)
        {
            EventQueue.invokeLater(new Runnable()
            {
                @Override
                public void run()
                {
                    new ExampleLayout().displayGUI();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's my search array: $aExt = array('png','jpg','gif'); I want to search through the variable:
Here is what I want to do. Use this HTML line and have the
Here's my situation. I have a DotNetNuke application. I want to link to an
Here is my html: <ul id=sub_nav class=block_hide trim no_list no_line style=display: block; left: 524.5px;>
Here's the code I have. It works. The only problem is that the first
Here is my demo code I want to disable td with this content 'CLICKING
Here is my code, works fine and prints out everything I want it to.
Here is the slightly modified source code for an example tray icon application I

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.