0

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.

1
  • What display technology are you using? HTML (JSP, JSF, Velocity, etc.), Swing, SWT, console output, something else? Also, note that the 'table' tag you've used says not to use it, and the row tag applies to databases rather than displaying rows. Commented May 28, 2015 at 16:55

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Or extend AbstractTableModel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.