aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextfield data in JTable row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextfield data in JTable row" Watch "JTextfield data in JTable row" New topic
Author

JTextfield data in JTable row

tadi raja
Ranch Hand

Joined: Jul 07, 2008
Posts: 109
Hi to all,

My problem in the code is that if i enter text in textfields and click on the button we get the data from textfield and displayed it on table row,can you please suggest me how it is possible ??

Here is the code ....
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand() == "ABC")
{
String st = _drug1.getText();
String st1 = _vehicle1.getText();
String st2 = _drug2.getText();
String st3 = _vehicle2.getText();
String st4 = _solution.getText();
}
}*****************************************************

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import java.util.*;

public class CustomTableModel extends AbstractTableModel
{
final String[] columnNames = {"Study","Drug1","Vehicle1","Drug2","Vehicle2","Solution","Finding"};

Vector rowVect = new Vector();

public int getColumnCount()
{
return columnNames.length;
}

public int getRowCount()
{
return rowVect.size();
}

public String getColumnName(int col)
{
return columnNames[col];
}

public Object getValueAt(int row, int col)
{
String[] rowData = (String[])rowVect.elementAt(row);
return rowData[col];
}

public boolean isCellEditable(int row, int col)
{
return false;
}

public void addRow(String[] str)
{
//str =
// str = GetDetails.str;
rowVect.addElement(str);
fireTableDataChanged();
//fireTableRowsInserted((rowVect.size()) - 1, rowVect.size());
}

public void removeRow(int row)
{
rowVect.remove(row);
fireTableDataChanged();
}

}

Thanks in advance
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

I have mentioned this before too. Please use CODE tags to make it easier for others to understand your code.

Instead of extending AbstractTableModel, use the DefaultTableModel.
It is two convenient methods which will be useful for you.


Also, if you haven't done so already, take a look at the JTable tutorial which can be found here


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextfield data in JTable row