creating tables with rows and colums


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: creating tables with rows and colums

  1. #1
    Join Date
    Feb 2005
    Posts
    24

    creating tables with rows and colums

    Hi guys

    I wanna create a table with 3 rows and 4 colums I havent designed tables before and this is my first time I was wondering if sumone can do me a small example with what goes at the start and end

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Check this

    Code:
    import javax.swing.*;
    import java.awt.*;
    import com.borland.dbswing.*;
    import javax.swing.table.*;
    import java.util.EventObject;
    import javax.swing.event.CellEditorListener;
    
    /**
     * <p>Title: Gym</p>
     * <p>Description: program snippets for exercise</p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: sjallejavamanscomany</p>
     * @author sjalle
     * @version 1.0
     */
    class ATableClass extends JTable {
      public Class getColumnClass(int column) {
        try {
          if (column == 0) {
            return Class.forName("java.lang.Boolean");
          } else if (column == 1) {
            return Class.forName("java.lang.Integer");
          }
    
          return Class.forName("java.lang.Object");
        }
        catch (ClassNotFoundException ex) {
          ex.printStackTrace();
          return null;
        }
      }
    }
    public class TableExample1 extends JFrame {
      JScrollPane jScrollPane1 = new JScrollPane();
      ATableClass tableOne = new ATableClass();
      DefaultTableModel model  = new DefaultTableModel();
      JCheckBox cbx=new JCheckBox();
      String [] sArray =new String [] {
        "lalala","lala"
      };
    
      Integer [] intArray = new Integer[] {
          new Integer(2),
          new Integer(77),
          new Integer(34),
          new Integer(5)
      };
      Boolean [] boolArray=new Boolean[] {
          new Boolean(true),
          new Boolean(false),
          new Boolean(true),
          new Boolean(false),
          new Boolean(true),
          new Boolean(false)
      };
    
      public TableExample1() {
        try {
          jbInit();
    
          tableOne.setModel(model);
          model.addColumn("CbxColumn", boolArray);
          model.addColumn("IDs", intArray);
          model.addColumn("Names", sArray);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public static void main(String[] args) {
        TableExample1 tex = new TableExample1();
        tex.setBounds(10,10,300,200);
        tex.setVisible(true);
      }
      private void jbInit() throws Exception {
        this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
        jScrollPane1.getViewport().add(tableOne, null);
      }
    }
    Last edited by sjalle; 03-22-2005 at 04:37 PM.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center