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

Similar Messages

  • JTable Column Names Not Displaying

    Hi there
    I create a JTable by passing the JTable constructor my custom TableModel which extends AbstractTableModel.
    For column names I have a String[] containing the column names in my custom TavleModel and have coded the TableModel methods accordingly.
    For some reason when I run the code the table is displayed, but the column names are not!?!
    Any advance is appreciated!

    Sorted!
    After looking at sample code in the JTable tutorial, it seems the table likes/needs to be added to a JScrollPane, as once I did this the column headings started appearing.
    e.g. JScrollPane scrollPane = new JScrollPane(table);

  • How to know column name (not an expression) used by function-based index?

    Hi guys,
    Is there any way to know exact column name used by FBI? If I correct, there is SYS.ICOLDEP$ table that has mapping between index/table columns, but I don't see how it could be uniquely joined with the rest. I know about USER_IND_EXPRESSIONS, but the task is to know exact column name, not it's expression.
    This required by our so-called SQL preprocessing of DB schema update utility, which parses stmt (INSERT in our case) and should check against PK/UNIQUE key values.
    Thanks!

    I don't think this is possible in 10g or 11g because :
    1. dictionary keeps track of column number in index and not in table
    2. the expression used in CREATE INDEX is a system generated column
    You would have to parse the expression from USER_IND_EXPRESSIONS:
    SQL> create table t(x int, y int);
    Table created.
    SQL> create index fbi on t(y+1);
    Index created.
    SQL> column index_name format a10
    SQL> column column_name format a20
    SQL> column column_expression format a10
    SQL> select i.index_name, ic.column_name, ic.column_position as iccn, ie.column_position as iecn, ie.column_expression
      2  from user_indexes i , user_ind_columns ic, user_ind_expressions ie
      3  where i.index_name = ic.index_name
      4  and i.index_name = ie.index_name
      5  and i.index_name =  'FBI';
    INDEX_NAME COLUMN_NAME                ICCN       IECN COLUMN_EXP
    FBI        SYS_NC00003$                  1          1 "Y"+1

  • Strange error "Invalid column name 'not applicable'

    When I am trying this piece of code on Solaris 10 having sybase ASE 12.5 installed :
    ResultSet rs = stmt.executeQuery("sp_helpdb master");
    while(rs.next()){
    System.out.println(rs.getString(1));
    I am getting the following error:
    Invalid column name 'not applicable'
    This query returns multiple result sets.
    I am able to print all values in the first result set only.
    Its failing in rs.next();
    I am using jConnect 5.2 driver.
    The same query is executing fine on Solaris 8 having ASE 12.0 installed.
    If i use :
    ResultSet rs = stmt.executeQuery("sp_helpdb master");
    then there is no problem in Solaris 10
    Plz help me.
    Its urgent

    You need to use execute() not executeQuery() in the scenario below and use the multi-result set logic
    If you are using jConnect, see the samples for an example.

  • My device icon in the left column does not appear. so, I can not make the sync.

    my device icon in the left column does not appear.
    so, I can not make the sync

    Device Not Recognised 
    For PC  >  http://support.apple.com/kb/TS1538
    For Mac  >  http://support.apple.com/kb/ts1591

  • Create Item column is not appearing in the "Personalize Page"

    Hi All,
    I am working in R12 upgrade project.
    I have to create item(Link) in a table region as per the requirement.
    But that "Create Item" button rather the column is not appearing in that "Personalize Page" when I click on the Personalize Page link of the concerned page.
    Can anyone please suggest Do I have to do any setup or any profile option needs to be enabled.
    Thanks,
    Raja Dutta

    Hi,
    Enable profile 'FND: Personalization Seeding Mode', clear the cache and check if this solves your problem.
    --Sushant                                                                                                                                                                                                                                                           

  • When trying to Forward, the addresses column does not appear

    When trying to 'forward' a message, the 'addressees' column does not appear and I cannot select recipients. This suddenly happened a short time ago and I can't figue out why.

    When you have a Write window open you toggle the Contact Sidebar on and off with the F9 key.

  • Error in COLMAP clause. Column name not found

    Hi guys,
    I must be missing something extremely simple here but I can't figure it out. I have a very simple test I am trying to perform. Remap a column from 1 table into another on replicat.
    I have created the defgens file.
    * Definitions created/modified 2013-02-12 13:08
    * Field descriptions for each column entry:
    * 1 Name
    * 2 Data Type
    * 3 External Length
    * 4 Fetch Offset
    * 5 Scale
    * 6 Level
    * 7 Null
    * 8 Bump if Odd
    * 9 Internal Length
    * 10 Binary Length
    * 11 Table Length
    * 12 Most Significant DT
    * 13 Least Significant DT
    * 14 High Precision
    * 15 Low Precision
    * 16 Elementary Item
    * 17 Occurs
    * 18 Key Column
    * 19 Sub Data Type
    Definition for table BILLING.B1
    Record length: 92
    Syskey: 0
    Columns: 2
    B_ID 64 50 0 0 0 1 0 50 50 50 0 0 0 0 1 0 1 2
    B_F_NAME 64 30 56 0 0 1 0 30 30 0 0 0 0 0 1 0 0 0
    End of definition
    Definition for table BILLING.B2
    Record length: 92
    Syskey: 0
    Columns: 2
    B_ID 64 50 0 0 0 1 0 50 50 50 0 0 0 0 1 0 1 2
    B_L_NAME 64 30 56 0 0 1 0 30 30 0 0 0 0 0 1 0 1 0
    End of definition
    I have setup the replicat to read the sourcedefs and remap the column
    -- Identify the Replicat group:
    REPLICAT rxtest
    -- State that source and target definitions are identical:
    --ASSUMETARGETDEFS
    SOURCEDEFS /u12/oracle/golden_gate_11_rep/dirsql/defgen_billing.sql
    --Discard Setup
    DISCARDFILE /u12/oracle/golden_gate_11_rep/dirout/rxtest.txt , PURGE
    SETENV (NLS_LANG="AMERICAN_AMERICA.WE8MSWIN1252")
    -- Specify database login information as needed for the database:
    USERID gg, PASSWORD
    -- Specify error handling rules:
    REPERROR (DEFAULT, ABEND)
    DDL EXCLUDE ALL
    MAP billing.b1, TARGET billing.r1,
    COLMAP (
    B_ID = id,
    b_f_name = f_name);
    Now when I try and start the rxtest replicat I get this error in the report.
    MAP resolved (entry BILLING.B1):
    MAP BILLING.B1, TARGET billing.r1, COLMAP ( B_ID = id, b_f_name = f_name);
    ...( B_ID = id, b_f_name = f_name...
    ^
    Error in COLMAP clause. Column name not found.
    Any ideas? Thanks

    desc billing.r1 - does that table have columns that you've included in the map clause?
    But, check the ordering of the columns in colmap - it goes target_column_name = source_column_name, looks like you have that reversed.
    I don't know why people insist on using SQL file extensions on def files, and placing them in the dirsql directory. What was wrong with using the (already created for you) dirdef directory? And naming the file with an extension like def or defs? It is not a SQL file.

  • Column names not visible in JTable

    Hello everyone,
    i have an Object array columns that i pass to the constructor of JTable, but for some reason the column names are not visible in my table.
    private final Object[] columns = {"Zeit", "Termin"};
    private Object[][] rows;
    //the next line fills the two-dimensional rows-array
    fillRows();
    //here the constructor
    JTable table = new JTable(rows, columns);
    table.setColumnSelectionAllowed(false);
    table.setDragEnabled(false);
              table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    TableColumnModel colModel = table.getColumnModel();
    TableColumn column = colModel.getColumn(1);
    column.setCellRenderer(new BookedCellRenderer(new int[] {3,4}));What are possible reasons/sollutions for this problem?

    Gosh, thanks! Usually i always use a jscrollpane for
    jtables and was about to use it too, but i got
    confused because of the headers when i tried to see
    whether the data in the table was right.You're welcome. The JTableHeaders object can be displayed in, say,
    the NORTH part of a BorderLayout while the JTable itself is displayed
    int the CENTER part. You can even display the headers SOUTH of
    the table itself if you like. A JTable object is quite flexible.
    kind regards,
    Jos

  • 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

  • Column Name not displaying in WinXP

    Hi,
    I have a custom JTable that has the contructor :
    public CustomMatrixTable(TableModel dm)
    super(dm);
    setAutoCreateColumnsFromModel(true);
    setColumnSelectionAllowed(true);
    setRowSelectionAllowed(true);
    setCellSelectionEnabled(true);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    The table model has overrides the getColumnName by retriving the name from a Vector.
    There are two coulmns in my example but the number can vary.
    In Windows 2000 it work perfectly. In XP the first column's name can be displayed but not the next.
    In fact the column header does not appear.
    please help.
    thanks
    Phill

    ok, it would seem that the work around is to declare a TableCellRenderer to be assigned as the column's header renderer. Unfortunately I have to do it for each column, nice if you want to make colourful column headers, but really one should be able to assign the column header renderer to be used by all column headers.

  • Domain Names Not Appearing In Drop Down of Data Cleansing Task

    For some reason, in several of my DQS data cleansing tasks, the domain names of the knowledge base I choose are not appearing. This is turn leads to an error message stating that "No domain field has been mapped to the input column...".
    The task can see the DQS server and it can see the various knowledge bases on that server, but the domains are not appearing.
    Has anyone else run into this issue?
    Thanks!!
    A. M. Robinson

    I have just found the same issue.
    For me, I believe it is because the domains are only used in matching rules, which the SSIS task does not support. Therefore they are not in the drop down as the SSIS DQS task cannot use them. Only map domains for data correction and you should be ok.

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

  • Easier way to set post-constructor JTable column names?

    I have a class that extends JTable. It also has a pair of inner classes that extend DefaultTableCellRenderer and AbstractTableModel so I can dynamicaly adjust the number of rows and their contents. That's not the problem - that part works fine. The problem is the column headers. My table doesn't currently have any but I want to add them.
    The column quantity is constant at 3 and should always be the same 3 Strings. It would be nice if I could use the JTable constructors that take a Vector or Object[] of column names from the start in my new class' constructor. But I don't think I can because at that point I don't know how many rows there will be or what they'll contain. Trying to set rowData to null just caused runtime exceptions.
    So the alternative seems to be to call setColumnModel() within the constructor, passing it a DefaultTableColumnModel. Which then requires I call addColumn() three times. Each time passing it a new TableColumn object. Each of which requires that I separately call setHeaderValue() after I construct it to set the header name. Am I right in that is the only way to do it? It just seems overly complex.

    I'll post a streamlined version of my class in case that will help...
    public class TotalsTable extends JTable
       private static int NUM_COLUMNS = 3;
       static final public String columnNames[] = {
             "Col Name 1", "Col Name 2", "Col Name 3"};
       protected Vector data = null;
       private TotalsModel tableModel;
       public TotalsTable()
          tableModel = new TotalsModel();
          setModel(tableModel);
          TableCellRenderer renderer = new TotalsCellRenderer();
          setDefaultRenderer(Object.class, renderer);
       public void updateTable(Vector pData)
          data = pData;
          tableModel.update();
       class TotalsCellRenderer extends DefaultTableCellRenderer
          public Component getTableCellRendererComponent
             (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
             super.getTableCellRendererComponent(table, value, isSelected,
                                                 hasFocus, row, column);
             if (column == 0) {
                setForeground(Color.blue);
             else {
                setForeground(Color.black);
             return this;
       class TotalsModel extends AbstractTableModel
          public TotalsModel()
             super();
          protected void update()
             fireTableStructureChanged();
           * Retrieves number of columns
           * (Necessary for AbstractTableModel implementation)
          public synchronized int getColumnCount()
             return NUM_COLUMNS;
          public synchronized int getRowCount()
             if (playerData == null)
                System.out.println("No rows found in table");
                return 0;
             else
                return playerData.size();
           * Returns cell information of a record at location row,column
           * (Necessary for AbstractTableModel implementation)
          public synchronized Object getValueAt(int row, int column)
             try
                MyObject p = (MyObject) data.elementAt(row);
                switch (column)
                   case 0:
                      return p.getName();
                   case 1:
                      return ("" + p.getDataItem2());
                   case 2:
                      return ("" + p.getDataItem3());
                   default:
                      System.out.println("getValueAt() Error: Invalid column");
             catch (Exception e)
                System.out.println("Exception in getValueAt(): " +
                                   e.getMessage());
             return "";
          public String getColumnName(int col)
             if (col < NUM_COLUMNS)
                return columnNames[col];
             else
                return "";
          public Class getColumnClass(int c)
             return getValueAt(0, c).getClass();
    }

Maybe you are looking for

  • What is the best way to create a week per page diary in indesign.

    I am currently working on a job designing an information pack for children. The document is A5 and i have been asked to insert diary pages (a week per page) at the back for December 2011 to January 2013. I am using indesign CS3. I know I can manually

  • SW6U2 (C++) wrong code with empty base class

    Consider this program: #include <assert.h> #include <new> struct Base1 int i; struct Base2 Base2() struct Derived : public Base1, public Base2 int main( int, char** ) int buf[2] = { 0x7F7F7F7F, 0x7F7F7F7F }; assert( sizeof( Derived ) == 4 ); new (buf

  • Flex form layout - add first child vertically aligned with label

    Hi all.. In flex form layout <mx:Form id="form">         <mx:FormItem label="horizontal:">             <mx:Text text="test"/>         </mx:FormItem> </mx:Form> the output will be horizontal 'test' But my constraint is i want to align the textbox(firs

  • Money overflow error

    Hi, When updating  a Purchase order we are getting Money overflow error but we are not changing any figures we are trying to add only remark so why are we getting this error please help regards

  • How to enable comments on Reader

    Hello, One of the main uses I had of Acrobat 9 was to enable comments on my PDF files for Adobe Reader. Now I upgraded to Acrobat XI, and I could not locate that option anywhere. I looked for it in the menus and the help, Googled it and searched here