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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:40:35+00:00 2026-06-18T05:40:35+00:00

The following code does not work on Mac OS X 10.6.8 but does on

  • 0

The following code does not work on Mac OS X 10.6.8 but does on everything else I test, Mac OS X Lion and Windows 7. The obvious explanation would be differences in Apple’s java. The table data does not show properly, if at all, on Mac. Here is the code

package com.dramble.dance;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

public class TableDemo extends JPanel {

    public TableDemo() {
        super(new GridLayout(1,0));

        TableModel tableModel = new TableModel();

        JTable table = new JTable(tableModel);

        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane);

        for(int i = 0 ; i <= 1900 ; i ++) {
            DataRow row = new DataRow(i,"Firstname"+i,"Lastname"+i);
            tableModel.appendRow(row);
            tableModel.fireTableRowsInserted(i, i);
        }
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        TableDemo newContentPane = new TableDemo();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private class DataRow {
        private String fname, lname;
        private Integer id;
        public String getFname() {
            return fname;
        }
        public String getLname() {
            return lname;
        }
        public Integer getId() {
            return id;
        }
        public DataRow(Integer id, String fname, String lname) {
            super();
            this.fname = fname;
            this.lname = lname;
            this.id = id;
        }
    }

    private class TableModel extends AbstractTableModel {
        List<DataRow> data;
        private String[] columnNames = {"ID #","First Name","Last Name"};
        private Class[] columnTypes = {int.class, String.class, String.class};


        public TableModel() {
            this.data = new ArrayList<DataRow>();
        }

        @Override
        public int getColumnCount() {
            return columnNames.length;
        }

        @Override
        public String getColumnName(int col) {
            return columnNames[col];
        }

        @Override
        public int getRowCount() {
            return this.data.size();
        }

        @Override
        public Object getValueAt(int row, int col) {
            DataRow dataRow = this.data.get(row);
            Object returnValue = null;

            switch (col) {
            case 0:
                returnValue = dataRow.getId();
                break;
            case 1:
                returnValue = dataRow.getFname();
                break;
            case 2:
                returnValue = dataRow.getLname();
                break;
            }
            return returnValue;
        }

        public void appendRow(DataRow row) {
            this.data.add(row);
        }

        @Override
        public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
        }

        @Override
        public Class getColumnClass(int col) {
            return columnTypes[col];
        }
    }
}

Here is an image of the expected behavior as exhibited in Windows
Working table on Windows

Here is the same code on Mac OS X 10.6.8
Broken on Mac OS X

  • 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-18T05:40:37+00:00Added an answer on June 18, 2026 at 5:40 am

    The problem lies in the AbstractTableModel, which came as a surprise to me for some reason, I figured it would be EDT and thread related for sure. The problem is in my array for the columnTypes and using int.class. Changing this to Integer.class fixed my issue.

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

Sidebar

Related Questions

The following code does not work correctly on Windows (but does on Linux): sock
How can I do this? (The following code does NOT work, but I hope
Following code does NOT work, but it expresses well what I wish to do.
Does anyone know why the following code does not work in FireFox but does
The following code does not work but I am using is as an example
I simply could not understand why the following code does not work. What could
If I use strict mode the following code does not work. It fails on
I have following code that does not work due to a being a value
I have following code that does not work: I never get to goToFoodDetail .
DataAnnotations does not work with buddy class. The following code always validate true. Why

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.