我有一个jtable的以下代码。它从数据库获取数据并填充表。
从数据库获取信息的代码:

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代码:

 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();


}


到目前为止,一切正常。现在,我需要添加另一个具有按钮的列,单击这些按钮可以查看该列的某些特定数据。我怎样才能做到这一点?
介意我是Java新手。提前致谢。

最佳答案

首先,变量名不应以大写字母开头。 “ InvoiceDetail”应为“ invoiceDetail”。您的大多数名字都是正确的。始终如一!!!

您可以使用Table Button Column

您只需在“标题”中添加一个字符串以表示列名,然后在“ invoiceDetails”中添加一个字符串以表示列中按钮的文本。

TableButtonColumn将为您提供渲染器和编辑器。

07-24 18:22
查看更多