Results 1 to 4 of 4
  1. #1
    AZMichael is offline Member
    Join Date
    Jan 2008
    Posts
    16
    Rep Power
    0

    Default [SOLVED] JTable DataModel - how to get

    Hi y'all;

    I am creating a project where I use a JTable that i create by specifying rows and columns
    for example:

    JTable jt = new JTable(10,30);

    So, how can I access (and manipulate) the underlying array if I have not used an array to create the table. That is, how can I get to
    jt DataModel DataVector elementData


    Thanks for your help.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
            JTable table = new JTable(10,10);
            Vector rows = ((DefaultTableModel)table.getModel()).getDataVector();
            for(int j = 0; j < rows.size(); j++) {
                Vector v = (Vector)rows.get(j);
                for(int k = 0; k < v.size(); k++) {
                    System.out.print("*");
                    if(k < v.size()-1)
                        System.out.print(" ");
                    else
                        System.out.println();
                }
            }
            Dimension d = table.getPreferredSize();
            d.width = 400;
            table.setPreferredScrollableViewportSize(d);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new JScrollPane(table));
            f.pack();
            f.setLocation(200,200);
            f.setVisible(true);

  3. #3
    AZMichael is offline Member
    Join Date
    Jan 2008
    Posts
    16
    Rep Power
    0

    Default

    Hey thanks. That was a big help. and got me to where I needed to be.

    :D

  4. #4
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Mark it as Solved please..... :)
    To finish sooner, take your own time....
    Nivedithaaaa

Similar Threads

  1. How to add in a new row in Jtable?
    By Ry4n in forum AWT / Swing
    Replies: 0
    Last Post: 01-18-2008, 01:26 PM
  2. JTable with Font
    By Rama Koti Reddy in forum AWT / Swing
    Replies: 1
    Last Post: 12-12-2007, 06:22 PM
  3. Help with JTable in java
    By carl in forum AWT / Swing
    Replies: 3
    Last Post: 08-11-2007, 10:47 PM
  4. Help with application with JTable
    By cachi in forum AWT / Swing
    Replies: 2
    Last Post: 08-08-2007, 09:51 AM
  5. Help with JTable
    By fernando in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 07:57 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
  •