NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

How to add/insert a new row into a Table component.

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
Glaursen



Joined: 20 Aug 2009
Posts: 8
Location: Phoenix

PostPosted: Thu Aug 20, 2009 3:57 am    Post subject: How to add/insert a new row into a Table component. Reply with quote

I am using NetBeans 6.1. I have a Table component on my page. I retrieve data and display it in my table. I want to include an Insert and Delete button to allow the user to directly add/delete rows in the table. I have seen some discussions on Jtable, but am confused if we are talking about the same component. I have references to my table1 component and the tableRowGroup1, but I am not seeing any methods to add, insert, or delete a row from the table1 or tableRowGroup1.

I have the following imports:
import com.sun.rave.web.ui.component.Table;
import com.sun.rave.web.ui.component.TableRowGroup;
import com.sun.rave.web.ui.model.DefaultTableDataProvider;

Can someone please point me in the right direction? I'm under a rather tight deadline or I would continue to play around until I figure it out.
Back to top
aljesco



Joined: 18 Aug 2009
Posts: 9

PostPosted: Thu Aug 20, 2009 10:18 am    Post subject: Re: How to add/insert a new row into a Table component. Reply with quote

Glaursen wrote:
I am using NetBeans 6.1. I have a Table component on my page. I retrieve data and display it in my table. I want to include an Insert and Delete button to allow the user to directly add/delete rows in the table. I have seen some discussions on Jtable, but am confused if we are talking about the same component. I have references to my table1 component and the tableRowGroup1, but I am not seeing any methods to add, insert, or delete a row from the table1 or tableRowGroup1.

I have the following imports:
import com.sun.rave.web.ui.component.Table;
import com.sun.rave.web.ui.component.TableRowGroup;
import com.sun.rave.web.ui.model.DefaultTableDataProvider;

Can someone please point me in the right direction? I'm under a rather tight deadline or I would continue to play around until I figure it out.


You have to create model for JTable and using this model for editing data in table.

Code:
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
   
    // Create a couple of columns
    model.addColumn("Col1");
    model.addColumn("Col2");
   
    // Append a row
    model.addRow(new Object[]{"v1", "v2"});
    // there are now 2 rows with 2 columns
   
    // Append a row with fewer values than columns.
    // The left-most fields in the new row are populated
    // with the supplied values (left-to-right) and fields
    // without values are set to null.
    model.addRow(new Object[]{"v1"});
    // there are now 3 rows with 2 columns
   
    // Append a row with more values than columns.
    // The extra values are ignored.
    model.addRow(new Object[]{"v1", "v2", "v3"});
    // there are now 4 rows with 2 columns

http://www.exampledepot.com/egs/javax.swing.table/AppendRow.html
Back to top
Glaursen



Joined: 20 Aug 2009
Posts: 8
Location: Phoenix

PostPosted: Thu Aug 20, 2009 4:06 pm    Post subject: Reply with quote

This is where I'm confused. I do not have a JTable on the page. I have a Table component. How do I get the row from the JTable into the Table component or how do I associate my Table component to the JTable?
Back to top
aljesco



Joined: 18 Aug 2009
Posts: 9

PostPosted: Thu Aug 20, 2009 5:24 pm    Post subject: Reply with quote

Maybe you should use JTable instead Table?
Does Table the gui component?
Back to top
Glaursen



Joined: 20 Aug 2009
Posts: 8
Location: Phoenix

PostPosted: Thu Aug 20, 2009 5:26 pm    Post subject: Reply with quote

Yes....Table is the drag and drop component provided by NetBeans.
Back to top
Franz
Posted via mailing list.





PostPosted: Thu Aug 20, 2009 7:26 pm    Post subject: How to add/insert a new row into a Table component. Reply with quote

Glaursen schrieb:
Quote:
I am using NetBeans 6.1. I have a Table component on my page. I retrieve data and display it in my table. I want to include an Insert and Delete button to allow the user to directly add/delete rows in the table. I have seen some discussions on Jtable, but am confused if we are talking about the same component. I have references to my table1 component and the tableRowGroup1, but I am not seeing any methods to add, insert, or delete a row from the table1 or tableRowGroup1.



I have the following imports:

import com.sun.rave.web.ui.component.Table;

import com.sun.rave.web.ui.component.TableRowGroup;

import com.sun.rave.web.ui.model.DefaultTableDataProvider;



Can someone please point me in the right direction? I'm under a rather tight deadline or I would continue to play around until I figure it out.

http://forums.netbeans.org/post-44933.html should help.

Regards
Back to top
Glaursen



Joined: 20 Aug 2009
Posts: 8
Location: Phoenix

PostPosted: Thu Aug 20, 2009 8:13 pm    Post subject: Reply with quote

That link is where the code example in the first response came from. I'm not understanding how to link my Table to the model or the JTable.

Is this even possible?
Back to top
aljesco



Joined: 18 Aug 2009
Posts: 9

PostPosted: Thu Aug 20, 2009 9:04 pm    Post subject: Reply with quote

Glaursen wrote:
That link is where the code example in the first response came from. I'm not understanding how to link my Table to the model or the JTable.

Is this even possible?


Object that you asking is JTable, not Table!

I told you in first responce what you need.

http://www.exampledepot.com/egs/javax.swing.table/AppendRow.html

"To add a row of data to a JTable component, you need to add it to its table model. A simple implementation of a table model that supports appending row data is DefaultTableModel. By default, a table uses a DefaultTableModel."

Here's working code:
Code:
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
   
    // Create a couple of columns
    model.addColumn("Col1");
    model.addColumn("Col2");
   
    // Append a row
    model.addRow(new Object[]{"v1", "v2"});
    // there are now 2 rows with 2 columns
   
    // Append a row with fewer values than columns.
    // The left-most fields in the new row are populated
    // with the supplied values (left-to-right) and fields
    // without values are set to null.
    model.addRow(new Object[]{"v1"});
    // there are now 3 rows with 2 columns
   
    // Append a row with more values than columns.
    // The extra values are ignored.
    model.addRow(new Object[]{"v1", "v2", "v3"});
    // there are now 4 rows with 2 columns


What don't you understand?
Back to top
Glaursen



Joined: 20 Aug 2009
Posts: 8
Location: Phoenix

PostPosted: Thu Aug 20, 2009 9:11 pm    Post subject: Reply with quote

This is the table component I have on my page that I dropped on from the NetBeans palette in the IDE.
import com.sun.rave.web.ui.component.Table;

This is the JTable that you are referring to.
import javax.swing.JTable;

There is a difference. I do not see a JTable component to drop onto my page from the NetBeans palette. If I'm missing something then I apologize. I saw numerous posts about what you are describing, but no one is addressing the Table that NetBeans lets you drag and drop on a page.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo