Hi Friends I am new to Java Swings. I am trying to add JTable. But the table is not displaying. I have the following java code (2 files)


package edu.ucsc.genome.qa.sigGateWay;

import java.io.*;
import java.util.*;

import java.awt.Color;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;

import edu.ucsc.genome.qa.sigData.KnownGene;
import edu.ucsc.genome.qa.sigGateWay.KnownGeneHtml;

public class KnownGeneGui extends JFrame

    JPanel topPane = new JPanel();
    JPanel downPane = new JPanel();

    Container contentPane;  
    JLabel label;
    JScrollPane scrollPaneDown = new JScrollPane();

    JButton nButton = new JButton("North");
    JButton sButton = new JButton("South");
    JButton eButton = new JButton("East");
    JButton wButton = new JButton("West");
    JComboBox comboBox = new JComboBox();
    private String sqlQuery[] = {"sql_1","sql_2","sql_3","sql_4","sql_5","sql_6"};  

    public KnownGeneGui()
        contentPane = getContentPane(); 
        contentPane.setLayout(new BorderLayout());

        comboBox = new JComboBox(sqlQuery);

        topPane.setMaximumSize(new java.awt.Dimension(1000,200));
        topPane.setMinimumSize(new java.awt.Dimension(1000,200));
        topPane.setPreferredSize(new java.awt.Dimension(1000,200));

        // add topPane to contentPane - not JFrame itself
        contentPane.add(topPane, BorderLayout.NORTH);

        label = new JLabel(sqlQuery[0]);

        // Size scrollPaneDown - leftPane size doesn't matter since it's the scrollable view
        scrollPaneDown.setMaximumSize(new java.awt.Dimension(1000, 700));
        scrollPaneDown.setMinimumSize((new java.awt.Dimension(1000, 700)));
        scrollPaneDown.setPreferredSize(new java.awt.Dimension(1000, 700));

        // set downPane as the scrollable component
        ItemListenerImpl itemListener = new ItemListenerImpl();

        // important to call revalidate here so leftPane will notify scrollPaneLeft to update accordingly
                contentPane.add(downPane, BorderLayout.SOUTH);
    private class ItemListenerImpl implements ItemListener
                public void itemStateChanged(ItemEvent ievent)
                        if(ievent.getStateChange() == ItemEvent.SELECTED)
                                        KnownGeneCgiTable kgTable = new KnownGeneCgiTable();
                                        if(kgTable != null)
                        if(comboBox.getSelectedIndex() == 1)
                            //Place Components in Container
                                            label.setText("      Your query is processing! Pl wait...Do not close the window!!!");
                                                    JTable table = kgTable.getKnownGeneCgiTable();
                                            else if(comboBox.getSelectedIndex() != 1)
                                                label.setText("Select the correct query"); 
                                                scrollPaneDown.add(new JButton("Error in table ...."));
                                 catch(Exception e)


    public static void main(String args[])
        KnownGeneGui g = new KnownGeneGui();


package edu.ucsc.genome.qa.sigGateWay;

import java.io.*;
import java.util.*;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;;

import edu.ucsc.genome.qa.sigData.KnownGene;
import edu.ucsc.genome.qa.sigSql.KnownGeneList;

public class KnownGeneCgiTable extends JFrame
    public static JTable getKnownGeneCgiTable() throws Exception
        List<KnownGene> kgList = KnownGeneList.getAllKnownGenes();   
        int total = kgList.size();

        String data[][] = new String[total][3];
        String headers[] = {"Known Gene Name","Chromosome","Protein ID"};

        if(kgList != null && kgList.size() > 0)
            int i = 0; 
            Iterator it = kgList.iterator();
                KnownGene kg = (KnownGene) it.next();   
                data[i][0] = kg.getName();
                data[i][1] = kg.getChrom();
                            data[i][5] = kg.getProteinId();
        return new JTable(new DefaultTableModel(data, headers)); 

Welcome biofly,
I think your code needs more .java files.

Read following before you post anything,
1.Homework policy
2.How to post source code?

Source code must be surrounded with code tags.
For example,

[CODE=Java] statements ....


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.