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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:02:34+00:00 2026-05-24T08:02:34+00:00

I have a GUI with a JTable using the DefaultTableModel. These instance variables are

  • 0

I have a GUI with a JTable using the DefaultTableModel.

These instance variables are declared:

boolean doRun = false;
Class clazz;
Object obyect;
DefaultTableModel model;
ArrayList<String> al = new ArrayList();

The table is populated by this:

public StatusGUI(Object invokerObject) {
    initComponents();
    setLocationRelativeTo(null);
    clazz = invokerObject.getClass();
    obyect = invokerObject;
    String line;
    try {
        Field[] fields = clazz.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if (!fields[i].isAccessible()) {
                fields[i].setAccessible(true);
            }
            if (("" + fields[i].getType()).equals("class java.lang.String")) {
                line = "String";
            } else {
                line = "" + fields[i].getType();
            }

            //Note: The first string in the Object is the description, which is left empty

            model.insertRow(0, new Object[]{"", fields[i].getName(), line, "" + fields[i]});
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    setVisible(true);
}

This generates (in this case) 5 rows containing information about variables.

I want to receive and store the information of these variables on button press with the following code:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    for (int i = 0; i < model.getRowCount(); i++) {
        String description = "" + model.getValueAt(i, 0);
        System.out.println("Description " + i + ": " + description);
        String name = "" + model.getValueAt(i, 3);
        if (!description.equals("") && description != null) {
            al.add(description + "::" + name);
        }
    }
    if (al.isEmpty()) {
        JOptionPane.showMessageDialog(this, "No descriptions were added to any of the variables."
                + "\nThis could also be because no variables were found - if so, please see 'Help'");
    } else {
        new Thread(new SendThread(al, obyect)).start();
        this.dispose();
    }
}                                        

When adding descriptions to all of the five rows, the above code generates the following output:

Description 0: d1
Description 1: d2
Description 2: d3
Description 3: d4
Description 4: 

When only adding a description in the first row of the JTable, the above code generates:

Description 0: 
Description 1: 
Description 2: 
Description 3: 
Description 4: 

This shows that it recognizes all five rows, but for some reasons messes up when reading from the rows.

I’ve been staring at the same lines of code for an hour now, and honestly don’t see what’s going wrong.

Thanks in advance,
Mike.

  • 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-05-24T08:02:35+00:00Added an answer on May 24, 2026 at 8:02 am

    My crystal ball says your table is still editing (line 5 in first example, line 0 in the second). Commit that edit first in the action performed.

    if (table.isEditing()) {
        table.getCellEditor().stopCellEditing();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GUI tool that manages state sequences. One component is a class
I have a JTable where I want to highlight some rows using a custom
I have GUI created using netbeans GUI builder. I want to add there an
I have a GUI which has a JComboBox and a JTable . The JComboBox
I have a GUI application within which i'm spawning a console application using Process
I have a JTable in a GUI and I want to return a number
Hi Im doing a project for college and have a JTable in my GUI.
I am working on a Java GUI, in which i have a JTable in
I have a GUI in java swing with a JTable and JButtons that implements
I have a GUI that is going to do a lot of disparate tasks.

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.