开发者

java running form table update problem form application

Hey i need your help about the code below. i m using netbeans, i have a user interface and i need to update a existing scrollpane with that table i have created dynamically but i cant find any way to do that for last 3 days could you help me out at this point?

dbcon.Connect();

String[] colu开发者_JS百科mnNames = {"First Name",
            "Last Name",
            "Sport",
            "# of Years",
            "Vegetarian"};
Object[][] data = {
    {"Kathy", "Smith",
     "Snowboarding", new Integer(5), new Boolean(false)},
    {"John", "Doe",
     "Rowing", new Integer(3), new Boolean(true)},
    {"Sue", "Black",
     "Knitting", new Integer(2), new Boolean(false)},
    {"Jane", "White",
     "Speed reading", new Integer(20), new Boolean(true)},
    {"Joe", "Brown",
     "Pool", new Integer(10), new Boolean(false)}};

 DefaultTableModel dtm = new DefaultTableModel(data,columnNames);
 JTable table = new JTable(dtm);
 // i created this table and can't update an existing Jscrollpane :(

exactly i need a way to refill a table of repaint a new table to an existing scroll pane

Any idea?


Have you tried looking at the JScrollPane documentation? I think doing something like this should work:

DefaultTableModel dtm = new DefaultTableModel(data,columnNames);
table = new JTable(dtm);
JScrollPane scrollPane = new JScrollPane(table);
this.add(scrollPane, BorderLayout.CENTER);


If I read the question correctly, the poster wants to update an "existing" scroll pane.

If this is the case then you just do:

scrollPane.setViewportView( table );

However, if you already have a table in the scrollpane then you don't even need to create a new JTable. All you need to do is update the model of the table:

DefaultTableModel model = new DefaultTableModel(...);
table.setModel( model ):
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜