如何在Java中添加数据行 [英] How to add data rows in Java

查看:95
本文介绍了如何在Java中添加数据行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!
伙计们,您能帮我如何在JTable中为每行添加数据吗?
我的代码在每行添加数据"中

m_patterncount-1是我的行计数器
piecetypes [0]是要插入到JTable中的样本数据.


Good day!
Guys, can you help me on how to add a data per row in my JTable?
I have here my code in "adding a data per row"

m_patterncount-1 is my row counter
piecetypes[0] is a sample data to be inserted in the JTable


String []strlist = {"Pattern Codes","Open Piece Types"};    //Column Header
DefaultTableModel model = new DefaultTableModel(null,strlist);
jtable = new javax.swing.JTable(model);

jtable.setModel(new javax.swing.table.DefaultTableModel(
    null,
    strlist
));

model.insertRow(m_patterncount-1, new Object[]{piecetypes[0]});



我只是遵循了一些教程,但仍然行不通.
我真的不知道为什么我的表不会显示任何数据.
也没有错误!

请帮忙!



i just followed some tutorials and still it wont work.
i really dont know why my table will not display any data.
There are no errors too!

Please help!

推荐答案

如何:
public InsertRows()
{
  JFrame frame = new JFrame("Inserting rows in the table!");
  JPanel panel = new JPanel();
  String data[][] = {{"Vinod","100"},{"Raju","200"},{"Ranju","300"}};
  String col[] = {"Name","code"};
  DefaultTableModel model = new DefaultTableModel(data,col);
  JTable table = new JTable(model);
  //Insert first position
  model.insertRow(0,new Object[]{"Ranjan","50"});
  //Insert 4 position
  model.insertRow(3,new Object[]{"Amar","600"});
  //Insert last position
  model.insertRow(table.getRowCount(),new Object[]{"Sushil","600"});
  panel.add(table);
  frame.add(panel);
  frame.setSize(300,300);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}



看看这些:
在JTable中插入行 [在JTable组件上附加行 [ JTable的简单方法 [ ^ ]



Have a look at these:
Inserting Rows in a JTable[^]
Appending a Row to a JTable Component[^]
A simple way to JTable[^]


这篇关于如何在Java中添加数据行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆