/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package schedule;

/**
 *
 * @author Kix
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;






public class Fourth extends JFrame {

   static JLabel lblFaccode,lblFaculty,lblSpace,lblSpace1;
   static JButton btnExit;
   static JTable tblOne;
   static GridBagLayout gbl;
   static GridBagConstraints gbc;


 


 public Fourth (String title){
        super(title);
        gbl=new GridBagLayout();
        setLayout(gbl);
        gbc=new GridBagConstraints();

        lblFaccode = new JLabel("Faculty Code");
        lblFaculty = new JLabel("Instructor");
        lblSpace = new JLabel(" ");
        lblSpace1 = new JLabel(" ");

        btnExit = new JButton("EXIT");
       
Object rows[][] = { { "AMZN", "Amazon", "67 9/16" },
        { "AOL", "America Online", "68 3/4" },
        { "BOUT", "About.com", "56 3/8" },
        { "CDNW", "CDnow", "4 7/16" },
        { "DCLK", "DoubleClick", "87 3/16" },
        { "EBAY", "eBay", "180 7/8" },
        { "EWBX", "EarthWeb", "18 1/4" },
        { "MKTW", "MarketWatch", "29" },
        { "TGLO", "Theglobe.com", "4 15/16" },
        { "YHOO", "Yahoo!", "151 1/8" } };
    Object columns[] = { "Symbol", "Name", "Price" };
    JTable tblOne = new JTable(rows, columns);
    tblOne.setAutoResizeMode (JTable.AUTO_RESIZE_OFF);

       
        gbc.fill=GridBagConstraints.HORIZONTAL;
        addComponent(lblFaccode,0,0,1,1);
        addComponent(lblSpace,1,0,1,1);
        addComponent(lblFaculty,2,0,1,1);
        addComponent(lblSpace1,3,0,1,1);
        addComponent(tblOne,4,0,10,10);



      
        setVisible(true);
        setSize(350,300);

 }

 public void addComponent(Component c,int row,int col,int width,int height){
        gbc.gridx=col;
        gbc.gridy=row;
        gbc.gridwidth=width;
        gbc.gridheight=height;
        gbl.setConstraints(c, gbc);
        add(c);

    }



 private void closeWindow(){

        addWindowListener(
            new WindowAdapter(){
                public void windowClosing(WindowEvent we){
                    System.exit(0);
                }
            }
        );

    }
 public static void main(String args[]){
        Fourth d = new Fourth ("DEPOSIT");

    }

}

Recommended Answers

All 3 Replies

And what other things else did you see when you ran your program?

only the records but there is no column name..

It is by design when you use JTable. If you want the header row of the table to be display, add a JScrollPane to wrap around your table instead. However, doing so will force you to set up a correct size for the table. If you just simply add the JScrollPane to it as of now, you would see that the table is displayed much smaller than it should be.

By the way, you should add the closing window right when you create your frame. If you don't, your program will do nothing after a user click "close" the window.

JScrollPane scrPane = new JScrollPane(tblOne);
  .
  .
  .
// instead of adding table, adding scroll pane here
addComponent(scrPane, 4, 0, a_width_number, a_height_number);
  .
  .
closeWindow();
  .
  .
Be a part of the DaniWeb community

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