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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:05:05+00:00 2026-06-01T10:05:05+00:00

How to place components in layout on specific position. Like I want to place

  • 0

How to place components in layout on specific position.
Like I want to place 2 text boxes in first row, below 3 combo boxes.

But when I am trying to put they all appear in one line and I have used flowlayout. I have used the border as well. When I am resizing, the window sizes of the components are going out from border.

Can you suggest me some layouts to use and how to use it?

Here is my code :

topPanel=new JPanel();
topPanel.setLayout(new FlowLayout());
topPanel.setBorder(new TitledBorder(new EtchedBorder(), "Customer Data"));

CNameTextField = new JTextField (20); // create the Customer Name text field
CNameTextField.setEditable(true);     // set editable text box

CIDLabel=new JLabel("Customer ID");

C_IDTextField = new JTextField (10);
C_IDTextField.setEditable(true);      // set editable text box

topPanel.add(CNameTextField);
topPanel.add(C_IDTextField);   

// Create and populate Room type combo box
roomTypeCombo = new JComboBox();
roomTypeCombo.addItem( "Budget($50)" );    

// Create and populate Meal type combo box
mealCombo = new JComboBox();
mealCombo.addItem( "None" );       

// Create and populate Days combo box

daysCombo = new JComboBox();

for(int i=0;i<31 ; i++) {
            // populate combobox with days
    daysCombo.addItem(i); 
}
    // Adding  rest of the components to top panel
topPanel.add(roomTypeCombo);
topPanel.add(mealCombo);
topPanel.add(daysCombo);

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-06-01T10:05:06+00:00Added an answer on June 1, 2026 at 10:05 am

    Try to change the layout.
    http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

    You could go for a GridLayout with two lines (for example, there is some others possible combinations), with each line containing respectively 3 JComboBoxs, and two JTextFields.

    Look carefully at the documentation and check out some examples easily reachable on the web.

    import java.awt.GridLayout;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class SwingResizeJFrame {
    
        public SwingResizeJFrame() {
            JTextField TextField1 = new JTextField("firstTextField");
            JTextField TextField2 = new JTextField("secondTextField");
            JPanel firstPanel = new JPanel();
            firstPanel.setLayout(new GridLayout(0, 2, 10, 10));
            firstPanel.add(TextField1);
            firstPanel.add(TextField2);
    
            JComboBox comboBox1 = new JComboBox(new Object[]{"Ester", "Jordi", "Jordina", "Jorge", "Sergi"});
            JComboBox comboBox2 = new JComboBox(new Object[]{"Ester", "Jordi", "Jordina", "Jorge", "Sergi"});
            JComboBox comboBox3 = new JComboBox(new Object[]{"Ester", "Jordi", "Jordina", "Jorge", "Sergi"});
            JPanel secondPanel = new JPanel();
            secondPanel.setLayout(new GridLayout(0, 3, 10, 10));
            secondPanel.add(comboBox1);
            secondPanel.add(comboBox2);
            secondPanel.add(comboBox3);
    
            JFrame frame = new JFrame();
            frame.setLayout(new GridLayout(2, 1, 10, 10));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(firstPanel);
            frame.add(secondPanel);
            frame.pack();
            frame.setLocation(150, 150);
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    SwingResizeJFrame demo = new SwingResizeJFrame();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to place the components A and B over component with List. I
How to achieve the following output in Java like windows Calculator, Example, First Row
I'm trying to use a sub window but either the components I try to
I am trying to implement some MVC-style UI components in Flex 4. I want
I have custom component that I can place in my layout file (XML) for
I'm trying to modify the text of a Label component that I already placed
My place of work currently uses CVS. A git migration is planned but it
I want to place a login inline-form in a twitter navbar. I have done
I'm trying to learn how to build apps for Android. The first simple app,
I have a GUI written using netbeans with a few simple components in place.

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.