JTable中:将一维数组作为行 [英] JTable: adding one dimensional array as rows

查看:184
本文介绍了JTable中:将一维数组作为行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的String [] =名称app1.getSimplifiedMovieRecordsList();

我有一个电影的名字这个字符串数组。我需要显示这些为具有一个列的表中的行。有人可以告诉我如何做到这一点。


解决方案

  

需要显示这些作为具有表的行一列


presuming你的意思是的JTable 为您的标题所暗示的:


  1. 的字符串数组转换为二维数组names.length行1列。

  2. 创建列名数组(长度为1)。

  3. 创建基于数据JTable中

例如:

 对象[] [] =资料表新对象[names.length] [1];
的for(int i = 0; I< names.length;我++){
    资料表由[i] [0] =名由[i];
}
[对象] colnames = {MyColumnNmae};
JTable的表=新的JTable(资料表,colnames);

您也可以:


  1. 创建基于一个的DefaultTableModel 使用相同的数据(便于修改)构建

  2. 直接使用字符串数组来创建一个 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:

  1. Convert the String array into a 2D array with names.length rows, and 1 column.
  2. Create the column name array (length 1).
  3. 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:

  1. Create a JTable based upon a DefaultTableModel constructed with the same data (facilitates modifications)
  2. Use the String array directly to create a JList

这篇关于JTable中:将一维数组作为行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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