This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Adding a row in a  table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding a row in a  table " Watch "Adding a row in a  table " New topic

Adding a row in a table

vijayaraghavan ganesan

Joined: Aug 23, 2006
Posts: 1
hi all,,,i need a help ....I hav a table and it fills the values from the database.but the table is editable. I use a table model. and in my code i need to add a new row at the end of the table after one row is filled by the user so tht the user can enter another value in a new row . so please let me know about adding a row automatically when the user fills the last row in the table.I include the code with this, thanks in advance...

public SetCustomAttributesPanel() {
new FormLayout(
"5dlu, Right ref:grow, 3dlu, Right ref, 5dlu",
"5dlu, pref, 0dlu, pref, 3dlu, pref, 3dlu, pref, 5dlu"));
CellConstraints cc = new CellConstraints();
JPanel tablePanel = new JPanel(
new FormLayout(
"pref:grow, 3dlu, pref",

tblCustomAttributes = new JTable();

//tmCustomAttributes = new CustomAttributesTableModel(null);

//tblCustomAttributes = new JTable(tmCustomAttributes);
JScrollPane scrollPane = new JScrollPane(tblCustomAttributes);
scrollPane.setPreferredSize(new Dimension(200, 300));
add(scrollPane, cc.xyw(2, 2, 3));
tablePanel.add(scrollPane, cc.xy(1, 1));

JPanel buttonPanel = new JPanel(new FormLayout("pref", "pref, 5dlu, pref"));
ButtonGroup bgAddDeleteType = new ButtonGroup();
btnDelete = new JButton(new AbstractAction(I18n.getString("set.customattributepanel.delete")){
public void actionPerformed(ActionEvent e) {
int[] selectedRows = tblCustomAttributes.getSelectedRows();
for (int i = selectedRows.length-1; i >= 0; i--) {

buttonPanel.add(btnDelete, cc.xy(1, 3));
tablePanel.add(buttonPanel, cc.xy(3, 1, "center, center"));
add(tablePanel, cc.xyw(2, 8, 3, "fill, fill"));

public void fillInPanel(OVOObjectInterface ovoObject) {
Rule rule = (Rule) ovoObject;
CustomRuleAttributes customRuleAttributes = rule.getSetAttributes().getCustomRuleAttributes();
tblCustomAttributes.setModel(new CustomAttributesTableModel(customRuleAttributes));
[ August 25, 2006: Message edited by: vijayaraghavan ganesan ]
I agree. Here's the link:
subject: Adding a row in a table
It's not a secret anymore!