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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:51:21+00:00 2026-06-12T12:51:21+00:00

i am currently coding a produkt system and I am designing the interface. My

  • 0

i am currently coding a produkt system and I am designing the interface. My Problem is, that the Interface is not in a colume. enter image description here I want it in one colume with my code code, also it would be good to add one more Button in the row of “suche nach waren”
Here is the code:

GroupLayout tLayout = new GroupLayout(mainFrame.getContentPane());
mainFrame.getContentPane().setLayout(tLayout);
tLayout.setAutoCreateGaps(true);
tLayout.setAutoCreateContainerGaps(true);

tLayout.setHorizontalGroup(tLayout.createSequentialGroup()
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tLabel0))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tLabel1)
                .addComponent(tLabel2)
                .addComponent(tLabel3)
                .addComponent(tLabel4))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tTextField1)
                .addComponent(tTextField2)
                .addComponent(tTextField3)
                .addComponent(tCombo)
                .addComponent(tButton1))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tTable))
        );

tLayout.setVerticalGroup(tLayout.createSequentialGroup()
        .addComponent(tLabel0)
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tLabel1)
                .addComponent(tTextField1))
            .addGroup(tLayout.createParallelGroup()
                .addComponent(tLabel2)
                .addComponent(tTextField2))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tLabel3)
                .addComponent(tTextField3))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tLabel4)
                .addComponent(tCombo))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tButton1))
        .addGroup(tLayout.createParallelGroup()
                .addComponent(tTable)));

Whats wrong with my code?
I appreciate your answer!

PS.: I do not want to use a layout editor because its my first time and I want to learn about SWING!

PPS.:

|Geben sie bitte die Kriterien für die Suche an:  
|Name:            (textfield)  
|Maximaler Preis: (textfield)  
|Alter des Kunden:(textfield)  
|Kategorie:       (Combo)  
|                 (Button)  
|Table....

Everything is in the right place except the upper label and the table

  • 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-12T12:51:23+00:00Added an answer on June 12, 2026 at 12:51 pm

    GridBagLayout Example…

    enter image description here

    You really should put the JTable inside a JScrollPane, it will take care of the header for you, but hay

    public class TestLayout {
    
        public static void main(String[] args) {
            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();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new FormPane());
                    frame.setSize(600, 300);
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    
        protected static class FormPane extends JPanel {
    
            public FormPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.gridwidth = GridBagConstraints.REMAINDER;
                gbc.anchor = GridBagConstraints.WEST;
    
                add(new JLabel("Geben sie bitte die Kriterien für die Suche an:"), gbc);
    
                gbc.gridwidth = 1;
                gbc.gridy++;
                add(new JLabel("Name:"), gbc);
                gbc.gridy++;
                add(new JLabel("Maximaler Preis:"), gbc);
                gbc.gridy++;
                add(new JLabel("Alter des Kunden:"), gbc);
                gbc.gridy++;
                add(new JLabel("Kategorie:"), gbc);
    
                gbc.gridx++;
                gbc.gridy = 1;
                add(new JTextField(10), gbc);
                gbc.gridy++;
                add(new JTextField(10), gbc);
                gbc.gridy++;
                add(new JTextField(10), gbc);
                gbc.gridy++;
                add(new JComboBox(), gbc);
                gbc.gridy++;
                add(new JButton("Click me"), gbc);
    
                gbc.gridy++;
                gbc.gridx = 0;
                gbc.gridwidth = GridBagConstraints.REMAINDER;
                gbc.fill = GridBagConstraints.HORIZONTAL;
    
                DefaultTableModel model = new DefaultTableModel(
                                new Object[][] {
                                    {"id", "Name", "Price", "Something", "Something", "Something"},
                                    {"NA", "NA", "NA", "NA", "NA", "NA"}
                                },
                                new Object[]{"id", "Name", "Price", "Something", "Something", "Something"});
    
    
                add(new JTable(model), gbc);
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently coding a mates portfolio and not to my surprise the code isn't loading
I am currently coding setup.py using setuptools. And I want to copy the static
I am currently coding some chat program and now want to play music via
I'm currently using a JavaScript coding style based on Douglas Crockford's Code Conventions for
I'm currently coding a product which will have only one database but will host
I am currently coding a web page that allows users to change local settings
I am currently coding a backup app for iOS, and I want to have
i am currently coding a simple Node.js based revision system: just commit , brunch
I'm currently coding an app that is mostly composed of forms. To do the
I'm currently coding a WP plugin and would need to override templates. My filter

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.