java - Trying to create a JTable with 2D vector and string array header, how do I do it? -
i'm returning errors jtable inserting 2d vector , string[] header...
try { refreshvector(); } catch (exception j) { throw j; } string[] headers = {"id","brand", "item", "details", "qty", "code", "re-order"}; jtable tbl_display = new jtable(data, headers); jscrollpane scrollpane = new jscrollpane(tbl_display); scrollpane.setbounds(120,120,600,300);
refreshvector method contains...
public void refreshvector() throws exception { dbconnect conn = new dbconnect(); try { conn.connect(); } catch (exception p) { throw p; } rs = conn.getdata(); while(rs.next()) { vector<object> vec = new vector<object>(); vec.add(rs.getstring("id_product")); vec.add(rs.getstring("brand")); vec.add(rs.getstring("description")); vec.add(rs.getstring("details")); vec.add(rs.getstring("quantity")); vec.add(rs.getstring("product_code")); vec.add(rs.getstring("reorder")); data.addelement(vec); } }
do have use table model? i'm trying create simple table displaying results of search in database. there way go without going table models , use standard table constructor. thank you.
do have use table model?
yes, relevant tutorial includes several examples. in particular case of database access, consider swingworker
, outlined here.
as aside, use layout manager rather setbounds()
.
Comments
Post a Comment