JTable column headers not showing up

I have a JTable inside a JScrollPane which, in turn, is inside a JTabbedPane.
I created a TableModel which extends AbstractTableModel as per the java Swing Tutorial examples.
In that model is an Object[][] object for the data called rowData, and all the data displays in the table perfectly.
I also have a String[] object called columnNames to define the column headers. ..the column names are coded directly into the object.
i.e.: String[] columnNames = {"John", "Janet", "Jamie", "Jennifer"};But the column names don't display at all.....all I get in the column headers is 'A', 'B', 'C', etc.
I need to know either
1)how to set this up correctly in the first place or
2)how I can reset the columns manually.
I have tried adding the table 2 ways..as follows...but neither one gets the headers right:
JScrollPane jScrollPane = new javax.swing.JScrollPane(getTable());or
JScrollPane jScrollPane.setViewportView(getTable());Note: getTable()..is where the new javax.swing.JTabel(new TableModel())stuff is done.
thx, ESW

You mentioned the you columnNames array. I suggest you declare it as static and accessible from within your custom table modelprivate static final String[] COLUMN_NAMES = {"John", "Janet", "Jamie", "Jennifer"};Then you override/implement the following methods in your TableModel :public String getColumnName(int column) {
     return COLUMN_NAMES[column];
public int getColumnCount() {
     return COLUMN_NAMES.length;
}That should do the trick.

Similar Messages

  • JTable column headers not displaying using custom table model

    Hi,
    I'm attempting to use a custom table model (by extending AbstractTableModel) to display the contents of a data set in a JTable. The table is displaying the data itself correctly but there are no column headers appearing. I have overridden getColumnName of the table model to return the correct header and have tried playing with the ColumnModel for the table but have not been able to get the headers to display (at all).
    Any ideas?
    Cheers

    Class PublicationTableModel:
    public class PublicationTableModel extends AbstractTableModel
        PublicationManager pubManager;
        /** Creates a new instance of PublicationTableModel */
        public PublicationTableModel(PublicationManager pm)
            super();
            pubManager = pm;
        public int getColumnCount()
            return GUISettings.getDisplayedFieldCount();
        public int getRowCount()
            return pubManager.getPublicationCount();
        public Class getColumnClass(int columnIndex)
            Object o = getValueAt(0, columnIndex);
            if (o != null) return o.getClass();
            return (new String()).getClass();
        public String getColumnName(int columnIndex)
            System.out.println("asked for column name "+columnIndex+" --> "+GUISettings.getColumnName(columnIndex));
            return GUISettings.getColumnName(columnIndex);
        public Publication getPublicationAt(int rowIndex)
            return pubManager.getPublicationAt(rowIndex);
        public Object getValueAt(int rowIndex, int columnIndex)
            Publication pub = (Publication)pubManager.getPublicationAt(rowIndex);
            String columnName = getColumnName(columnIndex);
            if (columnName.equals("Address"))
                if (pub instanceof Address) return ((Address)pub).getAddress();
                else return null;
            else if (columnName.equals("Annotation"))
                if (pub instanceof Annotation) return ((Annotation)pub).getAnnotation();
                else return null;
            etc
           else if (columnName.equals("Title"))
                return pub.getTitle();
            else if (columnName.equals("Key"))
                return pub.getKey();
            return null;
        public boolean isCellEditable(int rowIndex, int colIndex)
            return false;
        public void setValueAt(Object vValue, int rowIndex, int colIndex)
        }Class GUISettings:
    public class GUISettings {
        private static Vector fields = new Vector();
        private static Vector classes = new Vector();
        /** Creates a new instance of GUISettings */
        public GUISettings() {
        public static void setFields(Vector f)
            fields=f;
        public static int getDisplayedFieldCount()
            return fields.size();
        public static String getColumnName(int columnIndex)
            return (String)fields.elementAt(columnIndex);
        public static Vector getFields()
            return fields;
    }GUISettings.setFields has been called before table is displayed.
    Cheers,
    garsher

  • Workflow status column is not showing the internal status values (Inprogress, Started, Suspended, Completed)

    I've created SPD 2013 workflow and deployed them onto that document library, This workflow execute on item update event. When updating library item, workflow triggered and completed successfully but workflow status column is not
    showing the Internal Status values rather it is showing the Stage information. I've unchecked the "Automatically update stage name on workflow status" and republished the workflow. After that, it is still showing the stage information. Any help
    is really appreciated.

    Hi Venkadesh,
    It is by design that 2013 workflow will show stage name in the workflow status column when
    Automatically update the workflow status to the current stage name is checked.
    And the workflow status column will be blank when Automatically update the workflow status to the current stage name is unchecked.
    For existing workflows, the workflow status will still exists with the previous values after unchecking Automatically update the workflow status to the current stage name.
    We can use Set Workflow Status action to update the workflow status value based on our needs.
    Best regards,
    Victoria
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Autofit JTable column headers

    I have a problem. I am using eclipse. What i want to do is that in a Jtable, i want such a mechanism that no matter what the table headers are(any font, size), the jtable adjusts the column width to show the whole table header. The headers and the fonts are read from a file.
    presently i m doing this:
    //used to set the column widths
    FontMetrics metrics = tbl.getFontMetrics(tbl.getFont());
    // Set column widths
    int tempWidth;
    for (int i=0; i<columnNames.length ; i++)
    tempWidth = metrics.stringWidth(tbl.getColumnName(i))+ (2 * tbl.getColumnModel().getColumnMargin());
    tcm.getColumn(i).setPreferredWidth(tempWidth);
    tcm.getColumn(i).setPreferredWidth(columnNames.length()*7);
    The problem is that this does not work for all fonts.
    Can ne 1 plz provide sample code???

    Here's the full code I posted before to do this.
    It resizes the entire JTable to fit the column size, no matter what font properties, and
    optionally includes using the column header as well.
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=606240
    regards,
    Owen

  • Cant see jtable column headers

    I have my jtable in a container and i am displaying that container in a jframe. I cant see the table column headers. I cant use a jscrollpane and need to make the table headers visible. I can see the table fine with all its information in it. When I do a System.out.println(TableModel.getColumnName(int)); i get the correct column header name so I know that the column headers are existing. I would appreciate any help that you can give

    the last answer did not help me out. I reposted this with more information, such as i am placing my table in a container and not in a scrollpane. I added the code below and it still did not work
    content.add(jt.getTableHeader(), BorderLayout.NORTH);
    content.add(jt, BorderLayout.CENTER);
    I can still only see the table. I pasted code below where I create my table and repaint it. I have it set up where my table is in a JPanel. I have is set up so that I can move it around and resize it with the mouse. This all works and I can see the table but there are no headers.
    public FigTable(DefaultTableModel inTableModel, LEditor inLEditor)
              super(50, 50, 350, 200);
              setLineColor(Color.blue);
              setFillColor(ColorMenu.kColorOfNoFill);
              fEditor = inLEditor;
              content = fEditor.getGEFPanel().getDrawingPanel();
              importTable(inTableModel);
              fEditor.init();
              fEditor.inval();
    public void importTable(DefaultTableModel inTableModel)
              jt = new JTable(inTableModel);
              tRows = jt.getRowCount();
              tColumns = jt.getColumnCount();
              content.add(jt, BorderLayout.CENTER);
              content.add(jt.getTableHeader(), BorderLayout.NORTH);
    public void paint(Graphics g)
              jt.setBounds(_x, y, w, _h);
              if (_h >= tRows && tRows != 0)
              jt.setRowHeight(_h / tRows);
              if (isSelected())
                   drawHandles(g);
              if (_filled && (getFillColor() != null))
                   jt.setBackground(getFillColor());
              if (getLineColor() != null)
                   jt.setGridColor(getLineColor());
                   jt.setBorder(BorderFactory.createLineBorder(getLineColor()));
         }

  • JTable, column names not appearing!

    I am using the following code:
    Vector columnNames = new Vector();
            Vector data = new Vector();
            try
                //  Connect to the Database
                Common.Data.DataAccesser da = new Common.Data.DataAccesser();
                Connection connection = da.getConnection();
                //  Read data from a table
                String sql = "Select * from schedule1";
                Statement stmt = connection.createStatement();
                ResultSet rs = stmt.executeQuery( sql );
                ResultSetMetaData md = rs.getMetaData();
                int columns = md.getColumnCount();
                //  Get column names
                for (int i = 1; i <= columns; i++)
                    columnNames.addElement( md.getColumnName(i) );
                //  Get row data
                while (rs.next())
                    Vector row = new Vector(columns);
                    for (int i = 1; i <= columns; i++)
                        row.addElement( rs.getObject(i) );
                    data.addElement( row );
                rs.close();
                stmt.close();
            catch(Exception e)
                System.out.println( e );
            //  Create table with database data
            JTable table = new JTable(data, columnNames);
            jPanel2.setLayout(new java.awt.BorderLayout());
            jPanel2.add(table, BorderLayout.CENTER);I know its a bit messy, wat im tryin to do is add the table to the panel. the rows are showing perfectly but the column names do not show! Can anyone help?

    1) Please ask Swing questions in the Swing forum.
    2) Don't forget to specifically make the table header display. You do this by adding the table header to the jpanel in the borderlayout NORTH position, and you get the table header by calling getTableHeader. Have a look here for instance:
    http://forum.java.sun.com/thread.jspa?threadID=5235339&tstart=0

  • JTable column headers missing

    I created a JTable using:
    JTable table = new JTable(v,cN);
    where v is my vector that holds the data and cN is a vector to hold the column names as below:
    Vector cN = new Vector();
         cN.add("Registry Keys");
         cN.add("Program Name");
         cN.add("Key Type");
         cN.add("Drive");
         cN.add("Location");
         cN.add("Leave");It displays the table fine with the data and as I add or remove entries in the cN vector it adds and removes columns - but doesn't display column headers? Any help appreciated.

    Are you using a scrollpane? If not, you have to get the Table Header component and place it appropriately.

  • JTable column is not displaying in JPanel

    I created a JTable with single column like
    New JTable(celldata, columndata);
    and added it into JPanel. In this case only table cells are displying but not the column. If I use JScrollPane, table column name does displyed.
    Any help would be appreciated.
    Thanks
    Satheesh

    That is the correct behaviour of the components. A table won't display the column headers unless it's in a JScrollPane. Though you can get the headers from the table yourself manually using getTableHeader and put them where you want.

  • JTable column headers missing..kindly help...

    Hello there!
    I have written a program that ultimately deals with database connectivity, but my problem is got more to do with JTable. that's why i decided to post my doubt here.
    my program displays a JTable by reading fields form a database.
    But you see, the column headers are missing!!
    I have used the concept of DefaultTableModel, i first searched google and came upon a website: www.exampledepot.com and studied the sample codes on how insert fields into a JTable using the above....
    i swear to god i have done the exact same things..
    Could you please help me out??
    Thankyou very much and have a great day!
    :-)

    done that alreadyThen your problem is solved?
    Or does that mean that you had already done it and no headings showed up? In that case there's something wrong with your code.
    And Swing questions should be posted in the Swing forum.

  • SSRS Interactive Sort Headers Not Showing

    I've written a basic report 7 columns and added interactive sort, but the sort buttons do not show in my headers when i run the report, suggestions?

    Hi ,
    Interactive sorting based on Textbox Properties.
    So i'll suggest you to select first column Header textbox -> Textbox Proprties -> Interactive Sorting -> check enable option -> sort by column
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem.

  • Shared tab in left menu column does not show on one of the computers after setting up Home Sharing

    For iTunes 10.3, I have set up home sharing on two computers that run windows 7, I have authorized both computers.  The iTunes Shared link for computer 2 shows up on left column for computer 1(main iTunes computer).  The problem I am having is that the Shared link for computer 1 DOES NOT show up on computer 2.   My network between the both computers is working because I am able to pull/copy music files from computer 1 to computer 2.  Why doesn't the Shared link for Computer 1 show up on Computer 2 Itunes left column?  Any help would be most appreciated. Thank you.

    Nothing had changed when I plugged in my iPod at work today, having changed it to manage manually earlier at home. But after rebooting a few minutes ago, iTunes cranked up and updated the library. The library now appears below DEVICES/iPod on the menu instead of under LIBRARY/Music at the top left, which I'm pretty sure is different from before, but no matter. Also the iPod is still not appearing in My Computer but again, no matter. I am able to play my tunes on the work install of iTunes now and use iDump (which is a helluva lot less trouble than iTunes) to extract them.
    Thanks again for all the help.
    HP Pavilion, Dell Optiplex Windows XP

  • SharePont 2013 Document Library lookup Column Properties not Showing Correctly when editing in Word

    Hi
    I keep seeing this issue albeit intermittently.  I have set up a doc library for my users which has a custom content type (lookup, metadata columns, etc)  . They all appear perfectly most of the time except the lookup column. Sometimes is just
    decides to display the title field of the current library and not the lookup list title .  It is weird as it has been working perfectly for ages given the library is populated with valid documents.
    There are some fixes listed here. Has anyone got any experience of this?
    https://social.msdn.microsoft.com/Forums/azure/en-US/e0b55531-509c-4219-8113-61b3e488de69/document-library-metadata-properties-of-a-content-type-do-not-show-correctly-when-editing-in-word?forum=sharepointdevelopmentprevious
    Freelance consultant

    Hi,
    According to your post, my understanding is that the lookup  column not display well while editing in word.
    Did you customize the Document Information Panel?
    I recommend you edit your custom document information panel or create a new document information panel, then re-publish it to check whether it works.
    https://support.office.com/en-gb/article/Create-or-edit-a-custom-Document-Information-Panel-for-a-content-type-b701a9af-3ea6-4c1a-9e1c-75363bd987c9?ui=en-US&rs=en-GB&ad=GB
    Or you can also use the methods in the post you have pasted to check whether it works.
    As the limitation of the environment, we could not reproduce the issue in our environment.
    I  would suggest you open a case to Microsoft Customer Service via Phone.
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • HideShow: Column does not show label

    I have one hideShow region inside table, but it does not show label in column.
    Someone know help me?
    See the printscreen: http://www.flickr.com/photos/30358105@N03/3180588230/

    Hi,
    Under the “Identification” tab, there is a characteristic 0PSTNG_DATE. The corresponding 4th column is for Cube1, but Cube2 contains the posting date we are reporting on through the multiprovider. The third column  (“Equal To”) is NOT checked for Cube2.
    Could that be the problem? What is the significance of this checkbox not being checked for Cube2.
    On the other hand, I see 0PSTNG_DATE also under the fifth column (Char/NavAttrib), but the corresponding Cube3 and it is checked under “Equal To”
    Characteristic---Long_Description-Equal_To-In_InfoProvider-Char/NavAttrib
    0PSTNG_DATEposting dateCube1--
    Cube1
    Cube2               
    Cube2
    checked---Cube3--
    0PSTNG_DATE
    Cube3
    0FISCPER3-----Posting period---checked----Cube1             
    checked----Cube2               
    checked----Cube3               
    Checked----Cube4
    I hope the above info can from the Identification tab guide help?
    Can you help interpret these columns and the significance of the fact that there is no “checked” under “Equal To” for the Cube2 which is what actually feeds the column, TargetColumn (i.e the column which does not get populated with date when the Posting Date filed is set.
    Thanks.

  • Export JTable Column headers to Excel document

    Hello all!!! I am having a small problem while trying to export some data from a jTable to an excel document.
    I have a jTable and I use a custom TableModel with this:
    private String[] columnNames = {"First", "Second", "Third", "Forth"};as names for each column of the table.
    The thing I am trying to do is to export exactly the same "headers" from the columns of the jTable to the excel spreadsheet using Jakarta POI. Unfortunately I don't know how to do it and I haven't found anything yet on this forum. Can anyone help me with this?
    In simple words I want to know how I can have the same headers from my jTable columns, with the headers from the excel doument I will create.
    Many thanks in advanve!!!
    Kostas

    Thank you for your reply first of all. The problem is how to get the heading text and how to put it to the excel's first row OR to excels "headings" (if it is possible...). [in other words replace A,B,C,D from the excel document with the headers I get from the jTable...] .
    I hope now you can see what I am looking for... If there is no solution to this please tell me what are the alternatives. (B) could be a good example.
    Thanks you very much!!
    Kostas

  • JTable Column Headers are Squashed!

    Hi there,
    I'm using JBuilder, and have created a simple enough JTable that I place inside a JScrollPane. I am using my own implementation of the AbstractTable model.
    When I run the code, the Column headers are only about 5 pixels high! I have hunted around the JBuilder code (which if you have used JBuilder you will know is extensive!), but it doesn't seem to be doing anything extraordinary.
    So has anyone else had this problem? If so, what did you do to rectify.
    Yours hopefully
    Richard

    Hello there, my abstract implementation looks a little like this:
      public static final String columns[] = { "", "Request Id", "Date", "Component Name", "Version", "Type" };
      public String getColumnName(int columnIndex) {
        return columns[columnIndex];
      public Class getColumnClass(int columnIndex) {
        if (columnIndex == 0) {
          return Boolean.class;
        } else if (columnIndex == 1) {
          return Integer.class;
        } else {
          return String.class;
      }Thanks
    Richard

Maybe you are looking for

  • Calendar doesn't work

    Suddenly the calendar won't open on my mac mini, Mountain Lion 10.8.5 (maybe a recent upgrade, not sure).    Works fine on my iphone and ipad, sync-ing fine between those.  Is there a source from which I can download a new version of this app to the

  • ADF business component wizard with tables referencing junction table

    I have a three tables, user, devices and a link/junction table to map the user's assigned devices. <<user>> user_id user_name <<device>> device_id device_name <<userdevice>> user_id device_id I wanted to create a view page where I can search a user t

  • Firefox has been hijacked by Babylon Search, how do I get rid of it/

    I did not add Babylon Search. I deleted it from Add & Remove programs. It's gone from the list, but is still in Firefox. I removed it from Add-ons in Firefox. But it's still there. I've run ConboFix, but it's still there. How do I get rid of it?

  • Nokia 6300 Can't change contact details

    I have synchronised my phone with my PC. Now I am unable to change any of the contact details in my address book. If I enter a new contact and try to change it, it is possible. Any idea what I can do? Thanks

  • Can I download OS X 10.6

    Can I download the OS X 10.6 rather than purchasing it?