🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1443

Column Headers Don't Show in Table

#1443
From: Matthew Sweet
Date: Thu, 20 Nov 2003 17:23
97 lines
3676 bytes
I've created a table within a scroll pane, but the column headers don't show
up. They headers show up in the JBuilder9 IDE but when I run my application
the column headers don't show. The two rows of data that I created show up
fine. I've done other examples outside of JBuilder9 and column headers show
up fine. I feel like I,m missing something small like there's a parameter
I'm not setting to enable the column headers ot something.

I have a file called StigmergyTable Model.java:

import javax.swing.table.*;

public class StigmergyTableModel extends AbstractTableModel{
  private String[] columnNames;
  private Object[][] data;


  // StigmergyTableModel Class constructor
  public StigmergyTableModel( String[] cNames, Object[][] dataArg ) {
    columnNames = cNames;
    data = dataArg;
    }

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

     public int getRowCount() {
       return data.length;
     }

     public Object getValueAt(int row, int col) {
       return data[row][col];
     }

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

} // End class StigmergyTableModel

Another File where the above table model is instantiated.:

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

...

public class SimulationBuilder extends JPanel {

...

JPanel buildingAgentPanel = new JPanel();

...

String[] columnNames = new String[]
{"FileName","Path","Test","Test1","Test","Test1"};
    Object[][] data = new Object[][] {
{"somethigelse.txt","C:\\Folder","Test","Test1","Test","Test1"},
        {"somethigelse2.txt","C:\\Folder","Test","Test1","Test","Test1"}
    };

    StigmergyTableModel agentTableModel = new
StigmergyTableModel(columnNames,data);
    JTable agentTable = new JTable(agentTableModel);
    JScrollPane agentScrollPane = new JScrollPane(agentTable);

  public SimulationBuilder() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

 private void jbInit() throws Exception {

...

        agentTable.setToolTipText("");
        agentTable.setTableHeader(null);
        agentTable.setPreferredScrollableViewportSize(new Dimension(50,
50));
        agentScrollPane.add(agentTable, null);
        agentScrollPane.setViewportView(agentTable);
        agentScrollPane.setAutoscrolls(true);
        agentScrollPane.setOpaque(true);
        agentScrollPane.setBounds(new Rectangle(24, 73, 315, 99));
        buildingAgentPanel.add(agentScrollPane, null);

}

}
Technical Details
Message-ID: <3fbcf8fd@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!xmission!news-out.spamkiller.net!propagator2-maxim!news-in.superfeed.net!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,6f2d4b99ec92edf9,start
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-11-20 09:36:28 PST
Reply-To: "Matthew Sweet" <matthew.sweet@sed.redstone.army.mil>
From: "Matthew Sweet" <matthew.sweet@sed.redstone.army.mil>
Newsgroups: borland.public.jbuilder.java.swing
Subject: Column Headers Don't Show in Table
Date: Thu, 20 Nov 2003 11:23:53 -0600
Lines: 99
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 136.205.73.67
Message-ID: <3fbcf8fd@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1069349117 136.205.73.67 (20 Nov 2003 09:25:17 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!xmission!news-out.spamkiller.net!propagator2-maxim!news-in.superfeed.net!newsfeed01.tsnz.net!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail