Reputation: 2442
I have the following code for a jtable. it gets data from a database and populates the table. Code to get info from db:
Vector<Vector<String>> InvoiceDetails = new Vector<Vector<String>>();
Connection conn = dbConnection();
PreparedStatement pre = conn.prepareStatement("select * from CustomerDetails");
ResultSet rs = pre.executeQuery();
while(rs.next())
{
Vector<String> InvoiceDetail = new Vector<String>();
InvoiceDetail.add(rs.getString(1)); //Empid
InvoiceDetail.add(rs.getString(2)); //name
InvoiceDetail.add(rs.getString(3)); //position
InvoiceDetail.add(rs.getString(4));
//need to add code for button here
InvoiceDetails.add(InvoiceDetail);
}
jtable code:
public TableExample() throws Exception {
GetEmployeeDetails dbengine = new GetEmployeeDetails();
data = dbengine.getEmployee();
header = new Vector<String>();
header.add("invoicedata1");
header.add("invoicedata2");
header.add("invoicedata3");
header.add("invoicedata4");
//need to add button here
initComponents();
}
this is working fine as per now. Now I need to add another column which has buttons which I can click to view some specific data of that column. How can I do this? Mind that I am new to java. Thanks in advance.
Upvotes: 1
Views: 554
Reputation: 324118
First of all variable names should NOT start with an upper case character. "InvoiceDetail" should be "invoiceDetail". Most of your names are correct. Be consistent!!!
You can use the Table Button Column.
You simply add a String to your "header" to represent the column name and then add a String to the "invoiceDetails" to represent the text of the button in the column.
The TableButtonColumn
will provide the renderer and editor for you.
Upvotes: 2