Trouble viewing column headers JTable

I am having trouble with the column headers showing up. I have added a JScrollPane to the JTable, yet it fails to show up
Here is the array for the data and column headings:
     String[] tableheadings = {"","Jan", "Feb", "Mar","Apr","Jun", "Jul"};
     Object data[] [] = { { "Rent","","","","","",""},
                         {"Utilities","","","","","",""},
                         {"Groceris","","","","","",""},
                         {"Clothes","","","","","",""},
                         {"Bills","","","","","",""},
                         {"Automobile","","","","","",""},
and here is the method calling the array and placing into a JTable:
     public void doEside()
          east = new JPanel (new GridLayout(2,1));
          quote = new JLabel ("<HTML><FONT SIZE=+1><CENTER><B>\"Healthy</B>"
               +"<BR>Wealthy</BR>"
               +"<BR>and</BR>"
               +"<BR>Wise\"</BR></CENTER></FONT>", JLabel.CENTER);
          table = new JTable(data, tableheadings);
          DefaultTableModel dmodel = new DefaultTableModel(data, tableheadings)
               public boolean isCellEditable(int row,int column)
                    return false;
          table = new JTable(dmodel);
          table.setPreferredScrollableViewportSize(new Dimension( 200,70));
          table.getColumnModel().getColumn(0).setPreferredWidth(70);
          table.getColumnModel().getColumn(1).setPreferredWidth(10);
          table.getColumnModel().getColumn(2).setPreferredWidth(10);
          table.getColumnModel().getColumn(3).setPreferredWidth(10);
          table.getColumnModel().getColumn(4).setPreferredWidth(10);
          table.getColumnModel().getColumn(5).setPreferredWidth(10);
          table.getColumnModel().getColumn(6).setPreferredWidth(10);
          table.getTableHeader();
          JScrollPane sp = new JScrollPane(table);
          sp.add(table);
          east.add(quote);
          east.add(table);
          add(east, BorderLayout.EAST);
               

That's a Swing question, it should be asked in the Swing forum.
A JTable always represents the values provided by a TableModel.
The JTable constructor that directly takes the heading and data is just a convenience constructor which creates a DefaultTableModel and populates it using the supplied arguments.
You code extract creates two JTable object. The first one (the one with the data and headings) is lost for good after you reassign the variable table to the second JTavble instance. And this second instance is created with an empty DefaultTableModel.
What you want is probably to create one single JTAble object, using a model created as:
dtmodel = new DefaultTableModel(data, tableheadings);Edited by: jduprez on Nov 19, 2009 1:18 PM

Similar Messages

  • I keep getting an error message when i click view headers. i am unable to view column headers and am unable to sort by sender.

    erro message when i try to view full header (cannot view any header)

    Assuming that you are referring to '''email''' ''(based upon your use of the word sender''), Firefox doesn't do email, it's strictly a web browser.
    If you are using Firefox to access your mail, you are using "web-mail". You need to seek support from your service provider or a forum for that service.
    If your problem is with Mozilla Thunderbird, see this forum for support.
    [https://support.mozillamessaging.com/en-US/home] <br />
    or this one <br />
    [http://forums.mozillazine.org/viewforum.php?f=39]

  • Change Bridge Default List View Columns

    I only view specific image information and am continually moving the list view column headers around.
    Is there a way that you can set the default list view columns to display only what you need?

    Is there a way that you can set the default list view columns to display only what you need?
    You can create your own custom workspaces using the triangle next left to the search field top right Bridge window and choose new workspace.
    First you have to define your workspace by resizing or moving the panels to other locations (grab a panel tab and it will be surrounded by bleu lines, move to other location. A horizontal line means as a row in a column. A vertical line creates a column (max 3) and a surrounding line puts it in the same location as an extra tab.
    Use either menu view / list or use the default Metadata workspace that also shows list view.
    You can right click on the title of the column in list view and from the sub menu choose to insert or close certain columns. This is rather limited in options and the name column can't be altered at all (logically I would think…)
    Try playing around and when satisfied save it as new workspace and you can always revert to it by clicking on the workspace name and sometimes also needing to use the reset workspace button (workspaces are still far from perfect but in its current state also proved to be very useful).

  • Column headers and data are mismatched in Data tab of views after move col.

    Hi,
    Currently, I am using Windows XP, SQL Developer Version 1.2.1 Build Main 32.13.
    Java platform 1.5.0_06
    Oracle IDE 1.2.1.3213
    I'm having trouble with display of data from views in the "Data" tab of SQL Developer. If I move a column left or right of its original place, the data no longer line up with the proper column heading. The data are in the correct order, but the column headers are out of whack. Also, in the Single Record View, the data and column headers are mismatched.
    Refreshing the view, closing the view, closing and reopening SQL Developer do not "reset" the view so that the data and proper column headers are lined up. Even dropping and recreating the view does not force SQL Developer to use the proper data-column header match.
    Just to be clear, the data within the view is fine. It is the display of the data-column headers in the "Data" tab of SQL Developer (and the single record view) that is wrong. The mismatch seems to occur after a column is moved in the view.
    Is this a bug? I like the ability to move columns around within the display of the view. However, much more important that the column headers and data line up correctly.
    Thanks,
    Morgan

    Thanks much. I found the correct file, deleted it, and the column headers and data match up again.
    I found the correct file by searching the directory for one of the column names that occurs in the view (though I had to find both instances of "COLUMN_NAME" and "COLUMN NAME" (without the underscore)). Not sure why there were files with both versions.
    Do you know if there is any way to prevent those XXXXXXXXXTableSettings.xml files from writing all together (oracle.javatools.controls.nicetable.NiceTablePersistentSettings)? I looked through the SQL Developer preferences but nothing jumped out as being the setting to switch off.
    Should I be doing anything in particular to bring more attention to this potential bug so it might get fixed in a future release?
    Thanks again,
    Morgan

  • Hiding the column headers in boxed view

    I've created a custom list that I'm displaying in boxed view.  Here's a sample of the columns:
    Business Systems Manager
    Project lead
    Project number
    SFA?
    Etc...
    In boxed view, it displays like I have it here - vertical.  The names of the people and info display next to each item. 
    However, the web part is still displaying the column headings across the page like in this example:
    Business Systems Manager - Project Lead - Project Number - SFA? - etc...
    Some of my custom lists carry on for 12 or 13 columns and the main page view has about 6 or 7 of them so needless to say, the extra real estate the column headers (which are completely redundant because the column heading info is IN the boxed view!!!) are taking up is killing the layout of the page.
    Is there anyway to remove the column headers from the boxed view with out of the box Sharepoint?   Or is Designer required?
    Thanks!
    Lorraine

    This worked well for me:
    1) Add a Content Editor Web Part
    2) Click Source Editor
    3) Enter the following code:
    [css] <style> .ms-viewheadertr { display: none;} </style> [/css]
    4) Select Save
    5) Go to Layout and Select 'Hidden' 

  • 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

  • How can I add custom right-click-menu to column headers in JTable?

    Can anyone point me to a topic on how to customize a popup menu for column headers in JTable? Specifically, I want to add things like "auto-size column" and "hide column".
    Thanks,
    Matt

    Right-click on your table.  Then go to Advanced->Runtime Shortcut Menu->Edit.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Remove Column Headers from a JTable in a JScrollPane

    Hi,
    I'm just wondering how to remove the column headers from a JTable in a JScrollPane.

    Here are two ways to do it, with different visual outcomes...
    import javax.swing.*;
    public class Test {
        public static void main(String[] args) {
            Object[][] rowData = {{"A", "B"}, {"C", "D"}};
            Object[] columnNames = {"col 1", "col 2"};
            JTable table1 = new JTable(rowData, columnNames);
            table1.getTableHeader().setVisible(false);
            JScrollPane sp1 = new JScrollPane(table1);
            JTable table2 = new JTable(rowData, columnNames);
            final JScrollPane sp2 = new JScrollPane(table2);
            JPanel contentPane = new JPanel();
            contentPane.add(sp1);
            contentPane.add(sp2);
            final JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(contentPane);
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    sp2.setColumnHeader(null);
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }

  • 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 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 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

  • JTable Column Headers

    I want to create a JTable so that the table doesn't have any column headers. Right now I am using my own implementation of the AbstractTableModel Class for use with the tables, but if I leave out the public String getColumnName(int col) method, it makes the headers A, B, C, ... and if I set the column headers up with a blank String, it leaves an obvious thin empty header at the top. Any suggestions on how I can completely leave the column headers off?

    call the method on JTable
    table.setTableHeader(null);
    that will do the trick;
    cheers
    krishna

  • JTable -showing column headers and displaying multi-line strings

    Hi,
    This is two questions really.
    #1 - Does anyone know why my column headers aren't showing in my jtable using the model below?
    #2 - Does anyone know how I can display, mulitple line strings in a jtable? Currently my newline character ('\n') is just being displayed as a character.
    any help very much appreciated,
    Tom
    private class TaskHistoryTableModel extends AbstractTableModel {
    private List taskHistory = new ArrayList();
    public Object getValueAt(int row, int col) {
    if (col == 0) {
    return ((TaskHistoryItem) taskHistory.get(row)).getText();
    } else {
    return ((TaskHistoryItem) taskHistory.get(row)).getDate().getTime();
    public int getRowCount() {
    return taskHistory == null ? 0 : taskHistory.size();
    public int getColumnCount() {
    return 2;
    /** Getter for property taskHistory.
    * @return Value of property taskHistory.
    public List getTaskHistory() {
    return taskHistory;
    /** Setter for property taskHistory.
    * @param taskHistory New value of property taskHistory.
    public void setTaskHistory(List taskHistory) {
    this.taskHistory = taskHistory;
    public String getColumnName (int col) {
    return col == 0 ? "Text" : "Entered At";
    public boolean isCellEditable(int row, int col) {
    return false;
    }

    fixed my own problem - make your mulit-line string into html format e.g.
    this string will appear on two lines in a jtable
    "<html><p>A much more interesting entry</p> <p>on multiple lines</p></html>"

  • 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.

  • Vertical headers for columns in JTable

    Hi,
    I'm actually working on JTables and i'd like to set the headers of some columns to appear vertically instead of by default horizontal.
    I've found some tuts or examples to set the header on multiple lines but no one to set the header vertical...
    I want something like that :
    before :
    column1 | column2
    row1 |
    row2 |
    and after setting header columns vertical ( with column1 and column2 the column headers of my JTable )
    c | c
    o | o
    l | l
    u | u
    m | m
    n | n
    1 | 2
    ( and orientation of row headers not changed )
    Thanx for your reply
    Scottish

    Hi,
    Create you own colunm header renderer... it is actualy a cellRenderer. That cellRenderer should extends JLabel or JButton depending on what you want and you must put a paint method in it that draws the vertical text.
    JRG

Maybe you are looking for

  • When I open a new tab, then go to a new website, the back button doesn't work.

    For instance, I open craigslist in a new tab, then I click on "sporting goods". I try to click back to go back to the original craigslist page and the back button is not lit up and does not work. However if after I am on the sporting goods page (the

  • Itunes doesnt open  from iphone4S  (cannot connect to itunes Store [OK])

    Itunes doesnt open from my iphone gives message (cannot connect to itunes Store [OK]) I am from India .... I even restored the phone yesterday ... still the same thing .. App store is opening but itunes is not can anyone please help !!! Thanks

  • What to do when Safari WONT open

    on Friday night i bought a new copy of OS10.5 Leopard at the apple store i installed it Now when i click on Safari on the dock........It wont open i get an error message that Safari had to close unexpectedly whats wrong and how do i fix it?

  • My broser is redirected to another site

    After I do a Google search on a topic and click on a website from the search list my browser says; submit : Query and then I'm redirected to http://aconymfinder.com, which is not the site address I clicked on. I'm using windows XP professional with s

  • HT1338 MacBook Pro - HP printer issue

    I used to be able to print, but now the printer always says "offline".  What happened? I have a MacBook Pro purchased last Fall (2012) and an HP Photosmart C4500 Series printer.