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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:07+00:00 2026-06-13T00:51:07+00:00

I’ve just started using Java Layout manager, it’s been pretty difficult to get the

  • 0

I’ve just started using Java Layout manager, it’s been pretty difficult to get the GUI to behave as desired, so far:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;

    public class ex1 extends JFrame {

    private javax.swing.JButton AddBtn,perviousBtn,NextBtn;
    private javax.swing.JLabel LatLabel, LongLabel, EvlLabel;
    private javax.swing.JTextField LatText,LongText,EvlText;

    String columns[] = { "ID", "Name", "Age", "Gender" };
    Object data[][] = { { "0", "Tom", new Integer(20), "Male" },
            { "1", "Tina", new Integer(18), "Female" },
            { "2", "Raj", new Integer(19), "Male" },
            { "3", "Tina", new Integer(18), "Female" },
            { "4", "Raj", new Integer(19), "Male" },
            { "5", "Tina", new Integer(18), "Female" },
            { "6", "Raj", new Integer(19), "Male" },
            { "7", "Tina", new Integer(18), "Female" },
            { "8", "Raj", new Integer(19), "Male" },
            { "9", "Tina", new Integer(18), "Female" },
            { "10", "Raj", new Integer(19), "Male" }
    };

    public void addComponentsToPane(final Container pane) {

        JPanel compsToExperiment = new JPanel();
        GridLayout experimentLayout = new GridLayout(3, 3);
        compsToExperiment.setLayout(experimentLayout);
        JPanel Table = new JPanel();
        Table.setLayout(new GridLayout(8, 1));
        JPanel nav = new JPanel();
        nav.setLayout(new GridLayout(8, 3));

        LatLabel = new javax.swing.JLabel("Latitude: ");
        LongLabel = new javax.swing.JLabel("Longitude: ");
        EvlLabel = new javax.swing.JLabel("Elevation: ");
        LatText = new javax.swing.JTextField();
        LongText = new javax.swing.JTextField();
        EvlText = new javax.swing.JTextField();
        AddBtn = new javax.swing.JButton("Add");
        perviousBtn = new javax.swing.JButton("Next");
        NextBtn = new javax.swing.JButton("pervious");

        // perviousBtn.setPreferredSize(new Dimension(60, 60));

        compsToExperiment.add(LatLabel);
        compsToExperiment.add(LongLabel);
        compsToExperiment.add(EvlLabel);

        compsToExperiment.add(LatText);
        compsToExperiment.add(LongText);
        compsToExperiment.add(EvlText);
        compsToExperiment.add(AddBtn);

        // jButton1.addActionListener((ActionListener) this);
        // this.add(jButton1);

        JTable table = new JTable(data, columns);
        Table.add(table.getTableHeader());
        Table.add(table);

        nav.add(NextBtn);
        nav.add(perviousBtn);

        pane.add(compsToExperiment, BorderLayout.NORTH);
        pane.add(nav, BorderLayout.EAST);
        pane.add(Table, BorderLayout.CENTER);
    }

    /**
     * Create the GUI and show it. For thread safety, this method is invoked
     * from the event dispatch thread.
     */

    private static void createAndShowGUI() {

        ex1 frame = new ex1();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.addComponentsToPane(frame.getContentPane());
        frame.setSize(500, 500);
        //frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {

        try {    
            UIManager.setLookAndFeel(
                  "javax.swing.plaf.metal.MetalLookAndFeel");
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        /* Turn off metal's use of bold fonts */
        UIManager.put("swing.boldMetal", Boolean.FALSE);

        // Schedule a job for the event dispatch thread:
        // creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });    
    }    
}

Also I’m having issue to get table to display all the entry, it will only show the first 3 entries. Can you please help me to get the GUI tidy and with table issue.

  • 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-13T00:51:09+00:00Added an answer on June 13, 2026 at 12:51 am

    Take a look at these lines:

        JPanel Table = new JPanel();
        Table.setLayout(new GridLayout(8, 1));
    

    You should read the documentation on GridLayout carefully to use it in your code especially if you are using several layouts just like you do in your code. I suggest you design your components and their layouts on a scratch paper before you attempt to code them. Here, I changed your Table‘s layout’s parameters to this:

        Table.setLayout(new GridLayout(0, 1));
    

    And it displayed all the data entries. Here is what API says on GridLayout:

    public GridLayout(int rows, int cols)
    

    Creates a grid layout with the specified number of rows and columns. All components in the layout are given equal size.
    One, but not both, of rows and cols can be zero, which means that any number of objects can be placed in a row or in a column.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.