🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages Started by Matthew Sweet Thu, 20 Nov 2003 17:23
Column Headers Don't Show in Table
#1443
Author: 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);

}

}
Re: Column Headers Don't Show in Table
#1444
Author: Gillmer J. Derge (TeamB)
Date: Thu, 20 Nov 2003 17:35
29 lines
2246 bytes
"Matthew Sweet" <matthew.sweet@sed.redstone.army.mil> wrote in message
news:3fbcf8fd@newsgroups.borland.com...
>         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);

The table headers are displayed by a separate component, and there are
two reasons why it isn't displaying (not sure why it shows in the
designer).

First, you're not adding the table header component to your UI.  You
should probably add it as the scroll pane's column header.

    agentScrollPane.setColumnView(agentTable.getTableHeader());

Second, you're setting the table header to null, so in this case there
isn't actually a table header to add to the scroll pane.  You should
remove the line where you set the table header to null.

-- 
Gillmer J. Derge (TeamB)
Re: Column Headers Don't Show in Table
#1446
Author: Matthew Sweet
Date: Thu, 20 Nov 2003 20:45
45 lines
2911 bytes
Thanks. It's pretty obvious now. I think I was just looking at it too long
and the IDE was causing confusion.

Originally I had everything except for the
agentScrollPane.setViewportView(agentTable) and couldn't see my table at
all. Then I added the viewport part and could see the table when I ran my
application, but no header. For some reason I didn't think that I might have
to remove something rather than add something.

Thanks for your help.

Matthew Sweet

"Gillmer J. Derge (TeamB)" <spam@gillmerderge.com> wrote in message
news:3fbcfb74@newsgroups.borland.com...
> "Matthew Sweet" <matthew.sweet@sed.redstone.army.mil> wrote in message
> news:3fbcf8fd@newsgroups.borland.com...
> >         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);
>
> The table headers are displayed by a separate component, and there are
> two reasons why it isn't displaying (not sure why it shows in the
> designer).
>
> First, you're not adding the table header component to your UI.  You
> should probably add it as the scroll pane's column header.
>
>     agentScrollPane.setColumnView(agentTable.getTableHeader());
>
> Second, you're setting the table header to null, so in this case there
> isn't actually a table header to add to the scroll pane.  You should
> remove the line where you set the table header to null.
>
> -- 
> Gillmer J. Derge (TeamB)
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads