JTable中:将一维数组作为行 [英] JTable: adding one dimensional array as rows
本文介绍了JTable中:将一维数组作为行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的String [] =名称app1.getSimplifiedMovieRecordsList();
我有一个电影的名字这个字符串数组。我需要显示这些为具有一个列的表中的行。有人可以告诉我如何做到这一点。
解决方案
需要显示这些作为具有表的行一列
块引用>presuming你的意思是
的JTable
为您的标题所暗示的:
- 的字符串数组转换为二维数组names.length行1列。
- 创建列名数组(长度为1)。
- 创建基于数据JTable中
例如:
对象[] [] =资料表新对象[names.length] [1];
的for(int i = 0; I< names.length;我++){
资料表由[i] [0] =名由[i];
}
[对象] colnames = {MyColumnNmae};
JTable的表=新的JTable(资料表,colnames);您也可以:
- 创建基于一个的DefaultTableModel 使用相同的数据(便于修改)构建
- 直接使用字符串数组来创建一个 JList的
String[] names = app1.getSimplifiedMovieRecordsList();
I have this string array with names of movies. I need to display this as the rows of a table having one column. Can someone please tell me how to do this.
解决方案need to display this as the rows of a table having one column
Presuming you mean
JTable
as your title suggests:
- Convert the String array into a 2D array with names.length rows, and 1 column.
- Create the column name array (length 1).
- Create a JTable based upon the data
For example:
Object[][] tableData = new Object[names.length][1]; for ( int i = 0; i < names.length; i++ ){ tableData[i][0] = names[i]; } Object[] colnames = {"MyColumnNmae"}; JTable table = new JTable(tableData, colnames);
You can alternatively:
- Create a JTable based upon a DefaultTableModel constructed with the same data (facilitates modifications)
- Use the String array directly to create a JList
这篇关于JTable中:将一维数组作为行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文