繁体   English   中英

将按钮添加到从数据库中的数据动态生成的表的列中

[英]Add buttons to column in a table generated from data in a database dynamically java swing

我为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”。 您的大多数名字都是正确的。 始终如一!!!

您可以使用“ 表格按钮列”

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM