JTable not displaying column Heads

The following JPanel was constructed using JBuilder 7 (a horrendous piece of software) and is in GridBagLayout. I'm attempting to display the contents of a table using JTable, and whilst it displays the rows it doesn't display the columnHeads! What am I doing wrong?
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
public class BeginTask extends JPanel implements ActionListener{
private boolean dbupdated;
private MainFrame main;
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JTable jTable1 = new JTable();
private JButton jButton1 = new JButton();
private JButton jButton2 = new JButton();
private GridBagLayout gridBagLayout1 = new GridBagLayout();
private Connection connection;
private String url = "jdbc:odbc:bapers";
private String username = "";
private String password = "";
public BeginTask(MainFrame ma) throws SQLException{
main = ma;
logon();
drawTable();
try {
jbInit();
catch(Exception ex) {
ex.printStackTrace();
void jbInit() throws Exception {
jLabel1.setFont(new java.awt.Font("Dialog", 1, 18));
jLabel1.setText("Begin Task");
this.setLayout(gridBagLayout1);
jLabel2.setText("Select Task, and press OK.");
jButton1.setText("OK");
jButton2.setText("CANCEL");
jButton1.addActionListener(this);
jButton2.addActionListener(this);
this.add(jButton1, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(12, 117, 14, 0), 94, 8));
this.add(jButton2, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(19, 43, 7, 119), 62, 8));
this.add(jTable1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 25, 0, 22), 522, 281));
this.add(jLabel2, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 181, 0, 226), 13, 6));
this.add(jLabel1, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(29, 202, 0, 251), 19, 17));
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jButton1) {
if (dbupdated == true)
JOptionPane.showMessageDialog(null, "The database has been updated to show that the user has begun the task selected.");
else if (dbupdated == false)
JOptionPane.showMessageDialog(null, "The database has not been updated.");
else if (e.getSource() == jButton2) {
BapProcMain bpm = new BapProcMain(main);
main.redisplay(bpm);
public void logon() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection(url, username, password);
catch (ClassNotFoundException cnfex) {
System.err.println("Failed to load the JDBC/ODBC driver.");
cnfex.printStackTrace();
System.exit(1);
catch (SQLException sqlex) {
System.err.println("Unable to connect (SQL error)");
sqlex.printStackTrace();
public void logoff() {
if (connection == null) return;
try { connection.close(); }
catch (SQLException sqlex) {
System.err.println("Unable to disconnect (SQL error)");
public void drawTable() {
Statement stmt;
ResultSet rset;
try {
String query = "SELECT * FROM SpecificTask";
stmt = connection.createStatement();
rset = stmt.executeQuery(query);
displayResultSet(rset);
stmt.close();
catch (SQLException sqlex) {
sqlex.printStackTrace();
private void displayResultSet(ResultSet rs) throws SQLException {
// position to first record
boolean moreRecords = rs.next();
// if there are no records, display a message
if (! moreRecords){
JOptionPane.showMessageDialog (this, "No Specific Tasks to begin.");
return;
Vector columnHeads = new Vector();
Vector rows = new Vector();
try {
// get column heads
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 1; i <= rsmd.getColumnCount(); ++i)
columnHeads.addElement (rsmd.getColumnName(i));
//get row data
// System.out.println("Got this far. Check getNextRow(...)");
do { rows.addElement(getNextRow(rs, rsmd)); }
while (rs.next());
// display table with ResultSet contents
jTable1 = new JTable (rows, columnHeads);
JScrollPane scroller = new JScrollPane(jTable1);
// validate();
catch (SQLException sqlex) {
sqlex.printStackTrace();
private Vector getNextRow (ResultSet rs, ResultSetMetaData rsmd) throws SQLException {
Vector currentRow = new Vector();
for (int i = 1; i <= rsmd.getColumnCount(); ++ i)
switch (rsmd.getColumnType(i)) {
case Types.VARCHAR:
currentRow.addElement(rs.getString(i));
break;
case Types.INTEGER:
currentRow.addElement(new Long (rs.getLong(i) ) );
break;
default: System.out.println ("Type was: " +
rsmd.getColumnTypeName(i));
return currentRow;
}

The table header is shown automatically when you add the table to a scrollpane and then display the scrollpane in a panel. You use the following code to build the table/scrollpane:
// display table with ResultSet contents
jTable1 = new JTable (rows, columnHeads);
JScrollPane scroller = new JScrollPane(jTable1);
but, you add the table to your panel NOT the scrollpane:
this.add(jTable1, new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 25, 0, 22), 522, 281));
You should be adding the scrollpane to you panel.

Similar Messages

  • ALV footer not displayed, column header icons missing.

    Hi,
    My simple application uses the ALV grid, but the footer (showing the page number, next page icon, etc) does not display, even though there are pages and pages of data. This is in both Internet Explorer (6) and Firefox (I was expecting it to be an IE problem !).
    I have tried using the relevant method (though I think it should be visible by default):
    l_table->if_salv_wd_table_settings~set_footer_visible( value = IF_SALV_WD_C_TABLE_SETTINGS=>FOOTER_VISIBLE_TRUE ).
    but it still doesn't work. Other table settings methods do work (eg. setting the number of rows). Additionally, the icons for sorting columns do not appear in the column headers.
    I've searched on this forum, and looked for relevant OSS notes, but can't find anything. Any thoughts anyone ?
    Thanks,
    Nick.

    Hi
    Did u try with this code?
            lr_config->if_salv_wd_table_settings~set_visible_row_count( '5' ).
            lr_config->if_salv_wd_table_settings~SET_FOOTER_VISIBLE( '5' ).
    Regards
    Arun.P

  • How to display column header of a JTable in JScrollpane's RowHeader

    Can anyone tell me if it's possible to display the colum headers of a JTable which acts as the row headers of a JScrollpane object?
    If the answer is yes, could he/she point me to the right direction?
    Thanks,

    I'm guessing the answer is no because the column header is layed out horizontally and a row header is layed out vertically. But it should be easy enough to test:
    scrollPane.setRowHeaderView(table.getTableHeader());
    Its not hard to create your own row header. Search the forum using "+setrowheaderview +camickr" to find examples I've posted.

  • Problem in displaying Column Heading using JTable

    I am using JTable component in my applet. I am trying to retrieve records from a database and want to display the same in the table using JTable component. In that procees my data is shown in the table but I am not able to display the column heading.
    Please suggest.

    you could user JScrollPane to show the column's head.
    if you don't want to use JScrollPane ,you should use the getTableHeader() method and add the header into the pane

  • ADF swing: JTabbedPane does not display column names.

    Hi all,
    I have created an ADF Panel, which allows the user to run a few simple queries against an Oracle database done using ADF view objects and ADF view links and ADF application module.
    From the data control area I drag and drop a view link containing a query into a JTabbedPane. But when I run the ADF panel, JTabbedPane does not display the column headers from the SQL as opposed to JScrollPane which does.
    Suppose you do a select * from departments(dep_id, manager, state_cd), you will see all column headers meaning dep_id, manager, state_cd, and under each column the corresponding data which was retuned by the SQL if you use JScrollPane. But if you use you use JTabbedPane then you would only see the data which was retuned by the SQL without seeing the column header names meaning dep_id, manager, state_cd.
    What do I need to do to make JTabbedPane display columns headers?
    I would appreciate your input.
    Thanks.
    Bobby A.

    Hi,
    JScrollPane should be used. You can add this into a JTabbedPane if you like. Not all Swing panel show table headers
    Frank

  • Active Directory Users and Computer not displaying column data?

    I am running Windows 8.1 Enterprise with RSAT installed.  My Domain controllers are Server 2008 R2.
    I am having and issue with Active Directory Users and Computers.  Typically I will turn on Advanced Features and then add Columns for Email address and Display Name.  This for example allows me to easily export lists of users and there email
    addresses among other things.
    The issue is that on my Windows 8.1 client, the columns for Email and Display Name are empty.  It simply will not display this information.  It only displays Name, TYpe and Description.
    If I use a Windows 7 client, the information displays correctly.
    Has anyone run into this issue or heard of this problem when using ADUC on Windows 8.1?

    ADUC is an AD tool that is no longer being improved, with Microsoft now focusing on ADAC (Administrative Center). In 8.1, it has improved quite a bit since 7. You can also just try using the
    ActiveDirectory PowerShell Module, which is easy to use and fairly powerful. It can be simple to export lists, and the module for AD is included with RSAT tools.
    Example:
    Import-Module ActiveDirectory
    Get-ADUser -Filter {Manager -eq "John.Smith"} -Properties DisplayName,Mail | Export-Csv dump.csv -NoTypeInformation
    So, recommendation: either use ADAC, or PowerShell -- ADUC is part of the wave of deprecation.

  • ImageIcon loaded to JTable not displaying

    Hi!
    I have a JTable with my own table model based on a Vector of "MyRowType" class, wich has three components:
    String name;
    ImageIcon image;
    String comment;
    I fill the table with all that components and then i save the vector who is holding the information. What happens, is that when I load the vector I've saved, everything is displayed, in the table, the right way, but not the imageIcon.
    I know the saving and the loading of the file is correct, and I know the image is in the vector. All the needed classes implement Serializable.
    Can anyone tell me what do I have to do to make the image display?

    Hi!
    The problem is solved! Didn't use any of the suggestions.
    Because:
    -JTable has a default renderer for image Icons;
    -The images were displaying in the table correctly when I inserted the rows;
    -The problem was when I saved the vector and then loaded it from a file;
    -Images were loading correctly but not displaying;
    What I did was:
    for (int i = 0; i<myVector.size(); i++) {
    MyRowType row = (MyRowType)(myVector.elementAt(i));
    myRowType.setImage(new ImageIcon(etapa.getImage().getImage()));
    Witch means:
    -After I load the vector from file;
    -I recreate all the imageIcons in each row of the vector.
    This way it works!
    If there is a better way of doing this, please let me know, else if i've got no other answer in the next five days, I'm going to give the Dukes to gregory.smith that I think, it gave the best answer, although I didn't use it.

  • Not displaying column names in dynamic pages?

    I'd like to use a dynamic page as a detail page. In doing this I need a bit more freedom of design than what I now know is possible. Most important - I only need to print out the values returned by the SQL, not the column names as well. And I need to define the colors and fonts of the html table tags surrounding the returned values. How?
    It seems a bit strange that I am allowed to change the look and feel of the surrounding page elements through defining my own templates, and then have Oracle define how the elements placed in the templates are to appear.

    Hi,
    It is not possible to change the format the output coming from the <oracle> tags.
    Thanks,
    Sharmila

  • Web Page composer : new layout does not display Page Header Links Manager

    Hello,
    I am currently working with Web Page Composer, and this is my issue :
    when using original layout, the header are displayed with "Add to favorites", "Print", "E-mail" etc... and all chosen links via the "Select Page links" link.
    But whith my custom developped layout, I can choose wich links to display but they did not show up.
    I think my layout miss a configuration point, but I did not manage to find out which one.
    Does anyone have an idea ?
    Thanks a lot.
    Fabien.

    Hi Fabien,
    Probably, you might have missed something in the configuration part.
    Please ensure, you check all these steps, mentioned in here.
    http://help.sap.com/saphelp_nw70/helpdata/EN/45/d2970be57f4ebbe10000000a11466f/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/EN/45/d31ee7d4876f74e10000000a1553f6/frameset.htm
    Good Luck.
    Sandeep Tudumu

  • Favicon will not display and heads different

    http://www.dumasar.net/
    I have installed a favicon in the template upon which most, if not all of the pages on this site are based. The favicon displays fine on my local machine, but does not in the uploaded pages. I looked at the head of the template and the head of what is uploaded and they are different, despite repeated uploads. The site is on a yahoo server for what ever difference that may make.
    Here is the code for the template followed by the code on the uploaded pages:
    HEAD CODE ON TEMPLATE
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    <HEAD>
    <link rel="shortcut icon" href="images/dumasd.ico" />
    <!-- TemplateBeginEditable name="doctitle" -->
    <link rel="shortcut icon" href="images/dicon.ico">
    <TITLE> </TITLE>
    <!-- TemplateEndEditable -->
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <!-- TemplateBeginEditable name="head" -->
    <!-- TemplateEndEditable -->
    <link href="../css/dumas5-style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="../p7pm/p7popmenu.js"></script>
    <style type="text/css" media="screen">
    <!--
    @import url("../p7pm/p7pmv1.css");
    body {
        background-color: #006;
        text-align: center;
    -->
    </style>
    <!-- TemplateParam name="id" type="text" value="side-content" -->
    </HEAD>
    HEAD CODE ON UPLOADED INDEX PAGE
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML><!-- InstanceBegin template="/Templates/dumas5a.dwt" codeOutsideHTMLIsLocked="false" -->
    <HEAD>
    <!-- InstanceBeginEditable name="doctitle" -->
    <TITLE>Dumas Arkansas Home Page</TITLE>
    <!-- InstanceEndEditable -->
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <!-- InstanceBeginEditable name="head" -->
    <!-- InstanceEndEditable -->
    <link href="css/dumas5-style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="p7pm/p7popmenu.js"></script>
    <style type="text/css" media="screen">
    <!--
    @import url("p7pm/p7pmv1.css");
    body {
        background-color: #006;
        text-align: center;
    -->
    </style>
    <!-- InstanceParam name="id" type="text" value="side-content" -->
    </HEAD>
    What can I do?
    Thanks in advance,
    Joe

    Hi Joe,
    the first is this: <link rel="shortcut icon" href="images/dicon.ico">.
    I for my part use these advices, one of this code lines you should insert between the <head> </head> tags on your home or index.html page:
    <link rel="icon" href="pictures/favicon.ico" type="image/x-icon" /> (I use it) Upload the favicon.ico file to your server's root directory.
    If you wish to use an animated icon too, upload the animated_favicon1.gif as above and add this code line:
    <link rel="icon" href="animated_favicon1.gif" type="image/gif">
    ... AND! Our browsers must be "convinced" first to show favicon, so it might be that you have to do this too:
    - Clear ALL your caches!
    - Check with another browser, the new icon will be there (mostly at once).
    - If set, delete the bookmark to the page or re-create the bookmark.
    - Quit browser
    - Empty the Temp Internet Files Internet Options
    - Clear History
    - Delete everything in general, where the browser remembers visited sites.
    - Restart
    - Clear Site visit
    - Clear Bookmark
    After all these steps favicon should work as you like it.
    Hans-G.

  • Timestamp in JTable not displaying correctly

    Hi,
    I have a JTable with a custom TableModel in which one of the columns is a timestamp. When I occupy the table, all the dates show up as 1970-jan-01. They change to their proper values if they are selected or if the column is resized. Simply doing a table.selectAll(); table.clearSelection(); or setting the preferred size of the column back and forth after the data is changed does not help.
    Any ideas?

    aznan wrote:
    Any ideas?If you need further help lets start by showing us your Short, Self Contained, Compilable Example or SSCCE so that we can determine the problem.

  • Some pages not displaying columns properly since FF 37.0.1 update

    The problem showed up on some pages on Lynda.com. IE 11 does not have the problem.
    Here is a screen shot of a problem page on Lynda.com in FF, showing the column displaying wrongly:
    https://support.cdn.mozilla.net/media/uploads/images/2015-04-08-23-33-54-0d7e35.png
    And here is a screen shot of the same page in IE 11, displaying properly:
    https://support.cdn.mozilla.net/media/uploads/images/2015-04-08-23-35-00-77f7ad.png
    Troubleshooting steps so far:
    1. Refresh FF. No joy.
    2. Disable all add-ons. No joy.
    3. Run FF in safe mode. No joy.

    Never mind, I fixed it. Changed some Java settings, then changed them back.

  • Jtable not showing column Names

    I wrote the following Code and strangely it isn't showing the column Names....
    The mistake should be foolish..but i can't figure it out...
    can you please help.. or give any alternate way to do the same
    import javax.swing.*;
    import javax.swing.table.*;
    public class test
         public static String[] columnNames = {"User Name","User ID"};
         public static void main(String args[])
              JFrame frame = new JFrame();
              frame.setSize(400, 400);
              DefaultTableModel tabmodel = new DefaultTableModel(columnNames, 15);
              JTable table = new JTable(tabmodel);
              frame.add(table);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
    }

    Hi,
    A JScrollPane is needed to display the headers.
    import javax.swing.*;
    import javax.swing.table.*;
    public class TestTable {
        public static String[] columnNames = { "User Name", "User ID" };
        public static void main(String args[]) {
         // PB All GUI creation on the EDT
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
              JFrame frame = new JFrame();
              frame.setSize(400, 400);
              DefaultTableModel tabmodel = new DefaultTableModel(columnNames,
                   15);
              JTable table = new JTable(tabmodel);
              // PB frame.add(table);
              frame.add(new JScrollPane(table)); // PB
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
    }Piet

  • JTable not seeing Column names from Abstract table model

    Here is the code for the getColumnNames method
    It is getting called and it is send the correct data However the Headings do not match the data.
    public String getColumnName(int col){
    String s_retval;
    switch (m_iMode){
    case PhoneTableModel.NORMALVIEW:
    default:
    s_retval= m_sHeadingsDefault[col];
    break;
    System.err.println("TableNames "+s_retval);
    return s_retval;
    }

    Why do you show the part of the code that works?!
    Show how you create and display your table!
    What is displayed in the headings then?
    Which JDK on which platform?

  • Field Catalog not display column headings?

    Hi All,
    I have this type declared and I have created a table of this type
    TYPES:
         BEGIN OF ts_vip_display_sort,
           orgeh         TYPE orgeh,
           org_txt       TYPE string,
           org_chief_txt TYPE string,
           vip_amount    TYPE p LENGTH 10 DECIMALS 2,
           vip_payout    TYPE p LENGTH 10 DECIMALS 2,
           vip_diff      TYPE p LENGTH 10 DECIMALS 2,
           seqnr         TYPE sseqnr,
           vcount        TYPE vcount,
           level         TYPE slevel_d,
         END OF ts_vip_display_sort.
    I have specified each of the values I want to display on the screen but they are not showing up
      CLEAR et_fieldcatalog[].
      "org unit
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-fieldname  = 'ORGEH'.
      ls_fieldcatalog-coltext    = text-d01.
      ls_fieldcatalog-seltext    = text-d01.
      ls_fieldcatalog-scrtext_m  = text-d01.
      ls_fieldcatalog-colddictxt = 'R'.
      ls_fieldcatalog-col_pos    = 1.
      APPEND ls_fieldcatalog TO et_fieldcatalog.
    Function to display:
       CALL METHOD gr_alv_tree_control->set_table_for_first_display
          EXPORTING
            is_variant           = gs_variant
            i_save               = 'A'
            i_default            = 'X'
            is_hierarchy_header  = gs_hierarchy_header
            it_list_commentary   = gt_list_commentary
            it_toolbar_excluding = gt_toolbar_excluding
          CHANGING
            it_outtab            = gt_display_tab
            it_fieldcatalog      = gt_fieldcatalog.

    I am sure you already [read this |http://help.sap.com/saphelp_46b/helpdata/en/0a/b5533cd30911d2b467006094192fe3/content.htm] and the deceleration of the internal tables are correct.
    in bebug mode... verify if the gt_field* is holding the values.

Maybe you are looking for