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

  • Home
  • SEARCH
  • 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 8722495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:26:03+00:00 2026-06-13T07:26:03+00:00

I am kind of new to Java Programming and I am trying to make

  • 0

I am kind of new to Java Programming and I am trying to make a window that contains two buttons and a text area, as seen in the image below.
The problem I encountered though was positioning the components. I tried using GridLayout and separating the window into 9 rows and 16 cells, but then found I couldn’t make components occupy more than a cell. I know I should be using GridBagLayout but I don’t know how exactly. Help would be appreciated. 🙂

  • 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-13T07:26:04+00:00Added an answer on June 13, 2026 at 7:26 am

    You have a number of choices. Instead of trying to layout the whole component in one, try using a compound layout, where by you layout sections of the UI in separate panes and focus on the individual requirements of each section…

    enter image description here

    public class TestLayout11 {
    
        public static void main(String[] args) {
            new TestLayout11();
        }
    
        public TestLayout11() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException ex) {
                    } catch (InstantiationException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (UnsupportedLookAndFeelException ex) {
                    }
    
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new ExamplePane());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    
        protected class ExamplePane extends JPanel {
    
            public ExamplePane() {
                setLayout(new GridBagLayout());
    
                JPanel buttonPane = new JPanel(new GridBagLayout());
    
                JButton btnOkay = new JButton("Ok");
                JButton btnCancel = new JButton("Cancel");
    
                JTextArea textArea = new JTextArea(5, 20);
    
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.fill = GridBagConstraints.HORIZONTAL;
                gbc.anchor = GridBagConstraints.CENTER;
                buttonPane.add(btnOkay, gbc);
                gbc.gridy++;
                gbc.insets = new Insets(50, 0, 0, 0);
                buttonPane.add(btnCancel, gbc);
    
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.insets = new Insets(100, 100, 100, 100);
                add(buttonPane, gbc);
    
                gbc.insets = new Insets(150, 100, 150, 100);
                gbc.gridx++;
                gbc.gridy = 0;
                gbc.fill = GridBagConstraints.BOTH;
                add(new JScrollPane(textArea), gbc);                
            }            
        }        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to java programming and I would like to work on some kind
I'm kind of stumped here. I'm relatively new to Java/Programming in general. I want
I'm kind of new to C, but not to programming. I'm trying to create
I am kind of new to C (I have prior Java, C#, and some
I'm finding this kind of overriding after a new in java code very often
I've just started writing GAE web applications in Java so I'm kind of new
So I'm kind of new to this, I'm writing a WIN32 app that records
I want to make discussion form kind of website using java, should i just
i'm kind of new to java. I use eclipse and i imported some jar
Hey guys, sorry I'm kind of new to programming, but I had a small

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.