Results 1 to 5 of 5
- 10-09-2009, 08:50 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
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:
(initPropsTable() is called from the initComponents() function added by the NetBeans editor)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"); }
And then the row insertion, which is in another class.
I can copy and paste it exactly and put it in initPropsTable() and it will work there.Java Code:myApp.propsTableModel.insertRow(0, new String[]{"aa", "b"});
The data there was just for testing, but it happens with any data type. What might be the problem?
- 10-09-2009, 10:26 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
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.I can copy and paste it exactly and put it in initPropsTable() and it will work there.
If you need more help then post a proper SSCCE
- 10-09-2009, 11:43 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
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
in did the trick.Java Code:Thread.sleep(500);
-
-
I hate to say it but this solution smells bad. Without more info, that's about all I can tell.
Similar Threads
-
Highlight rows of a jtable
By simmi in forum AWT / SwingReplies: 5Last Post: 08-20-2009, 01:13 PM -
JTable, deselecting rows gives ArrayIndexOutOfBoundsException
By hendrix79 in forum New To JavaReplies: 0Last Post: 01-23-2009, 04:36 PM -
JTable in Frame only shows 3 rows
By Laura Warren in forum New To JavaReplies: 4Last Post: 12-24-2008, 05:48 AM -
Deleting All rows in the JTable
By surot in forum New To JavaReplies: 1Last Post: 04-16-2008, 10:44 AM -
display rows in jtable
By osval in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks