Results 1 to 5 of 5
  1. #1
    Jacob_ is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default JTable insertRows() just adding blank rows

    I can insert rows in my JTable while it is being created in initComponents(), but trying to insert rows later results in completely blank rows being added. Here is my code.

    Initialization part:

    Java Code:
        public static JTable propsTable = new JTable();
        public static DefaultTableModel propsTableModel = new DefaultTableModel();
        public static void initPropsTable()
        {
            propsTable.setModel(propsTableModel);
            propsTableModel.addColumn("Property");
            propsTableModel.addColumn("Value");
        }
    (initPropsTable() is called from the initComponents() function added by the NetBeans editor)

    And then the row insertion, which is in another class.

    Java Code:
            myApp.propsTableModel.insertRow(0, new String[]{"aa", "b"});
    I can copy and paste it exactly and put it in initPropsTable() and it will work there.

    The data there was just for testing, but it happens with any data type. What might be the problem?

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I can copy and paste it exactly and put it in initPropsTable() and it will work there.
    Well, if both methods have access to the same TableModel then it should work fine. Display the TableModel in both locations to make sure you have access to the same model.

    If you need more help then post a proper SSCCE

  3. #3
    Jacob_ is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks! With some experimenting, I figured it out--the class was executing at the start of the program, so the UI hadn't had time to create itself... Throwing a

    Java Code:
            Thread.sleep(500);
    in did the trick.

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

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

Similar Threads

  1. Highlight rows of a jtable
    By simmi in forum AWT / Swing
    Replies: 5
    Last Post: 08-20-2009, 02:13 PM
  2. Replies: 0
    Last Post: 01-23-2009, 05:36 PM
  3. JTable in Frame only shows 3 rows
    By Laura Warren in forum New To Java
    Replies: 4
    Last Post: 12-24-2008, 06:48 AM
  4. Deleting All rows in the JTable
    By surot in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 11:44 AM
  5. display rows in jtable
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:54 PM

Tags for this Thread

Posting Permissions

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