Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    88
    Rep Power
    0

    Default Complet details of jtable and renderer

    Hello user based on my search on JTable i am posting this thread, If any correction in this post please reply.
    JTable is one of the difficult component in swings.

    Creating a JTable


    JTable jt=new JTable();

    The above create code create jtable.
    Adding ScrollPane to table


    JScrollPane jsb=new JScrollPane(jt);

    Creating a Default Table Model



    DefaultTableModel dt=new DefaultTableModel( new Object[][] , new Object[] {" Column Name1 ", ".....", "Column nth name"});
    jt.setModel(dt);



    Setting Number of rows


    we cant set no.of rows to using jtable.

    First get the table model and set number of rows

    jt.getModel().setRowCount(n); //n is any integer
    these are the simple task on jtable.




    Add a component to jtable column model




    For add a component to jtable column we should use ediotors/ renders

    i am explaining using jcombobox.

    first get the column model

    TableColumnModel tcm=JTable.getColumnModel();


    Then use Editor

    tcm.getColumn(nth column).setCellEditor(new DefaultCellEditor(jcombobox));


    in the similar way we can add diffrent components in jtable column.

    The above procuder will create a jcombobox in nth column in every row of nth column.
    if we need to add diffrent components in single column in diffrent rows use cell render.
    Last edited by anilkumar_vist; 12-12-2009 at 03:17 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    On first glance, this appears wrong:
    Java Code:
    //Adding ScrollPane to table
    JScrollPane jsb=new JScrollPane();
    jsb.add(jt);
    Better:
    Java Code:
    //Adding ScrollPane to table
    JScrollPane jsb=new JScrollPane(jt);
    //jsb.add(jt);
    or
    Java Code:
    //Adding ScrollPane to table
    JScrollPane jsb=new JScrollPane();
    jsb.getViewport.add(jt);
    The JScrollPane tutorial and API will explain all this.


    So, rather than have us grunge through your other bits of code and such, why not tell us exactly where you're having problems.

Similar Threads

  1. what is and how works the first ?, example.com/details?page=4
    By lse123 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 10-29-2009, 03:18 PM
  2. jtable cell renderer
    By ankitmcgill in forum New To Java
    Replies: 2
    Last Post: 05-22-2009, 02:08 AM
  3. socket details
    By rob in forum Advanced Java
    Replies: 8
    Last Post: 03-03-2009, 03:33 PM
  4. how to use renderer in JTable
    By sunilpatel28 in forum Advanced Java
    Replies: 0
    Last Post: 12-09-2008, 09:01 AM
  5. WAR issue,please see the details
    By milindvijayshah@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 07-25-2008, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •