jTable problem
hello,
I am creating one jFrame , in that I create one jpanel. I am using netbeans.
I put one jTable and one jButton.
for my work, when I click add button, I need to add one row in the jTable. I try it in netbeans. but, table is not added.
please anyone give me some example codes for dynamically adding rows when we click button.
[361 byte] By [
rameshsa] at [2007-11-26 23:41:44]

# 3
hello,
actually, I am using"DefaultTableModel model;'.
but in this , addRow only add objects. but I have string value when I get from textfield.
so, i need to convert this string to object and put it in addRow.
how can i convert the string to object.
or is it possible to add the jTextField string to jTable rows one by one.
.
# 5
hello,
I know about it (string is an object);
but, problem is ,
String LETTERS ;
JTable table;
DefaultTableModel model1;
JPanel buttonPanel;
JTextField tf1, tf2, tf3, tf4;
tf1 = new JTextField(10);
model1.addRow(LETTERS1);
F:\src\src\mainPack\MainFrame.java:149: ';' expected
model1.addRow(LETTERS1);
how can I add textfield string to jtable.
i am new to that gui things, jtable. thats why i have problems
# 7
hello sir,
i left one line of code.
LETTERS1 = tf1.getText();
String LETTERS ;
JTable table;
DefaultTableModel model1;
JPanel buttonPanel;
JTextField tf1, tf2, tf3, tf4;
tf1 = new JTextField(10);
LETTERS1 = tf1.getText();
model1.addRow(LETTERS1);
the error it shows,
F:\src\src\mainPack\MainFrame.java:149: ';' expected
model1.addRow(LETTERS1);
whats my problem.
# 10
hello camickr,
thanks for your valuble example.
I used that concepts, but here problem is, I am getting input from JTextField ad string. I create one btton "add" and click that button, that textfield string input must add in that row one by one. But, when I give in put to string and click "add" button, it throws exception (I thing it from addRow() method).
your code is,
button = new JButton( "Add Row" );
buttonPanel.add( button );
button.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
model.addRow( createRow() );
int row = table.getRowCount() - 1;
table.changeSelection(row, row, false, false);
table.requestFocusInWindow();
}
});
..
.
.
.
.
private Object[] createRow()
{
Object[] newRow = new Object[2];
int row = table.getRowCount() + 1;
newRow[0] = Integer.toString( row );
newRow[1] = LETTERS.substring(row-1, row);
return newRow;
}
here problem is, addRow only accepts Object[] values. When I add text field string input it give error. I am using netbeans.
shall I need to convert that string object into Object{} array or something.
please, give me some explanations.
i my program, I am assiging textfield getText to the String LETTERS1 and try to add it to the row. but, I get error.
what can i do,sir.
Thank you.