views:

194

answers:

1

I'm creating a Java application where the user can search through a list of objects, which are then displayed in a JEditorPane window using a dynamically generated table whose size varies by the amount of results returned.

I then want to allow the user to select and edit the objects. (The Java objects, not the HTML code) Is this feasible, or should I be doing something completely different? Should I even be using a JEditorPane, or should I be using a different method, and how would I go about that?

The display in question has anywhere from 1 to 50 (depending on the results) cells that read like this:

Name
Text
a picture of the object
year
check boxes for two boolean variables that are part of the object.

The check boxes should allow the user to click on them and change the boolean variables, which would then be saved to the main object collection.

Thoughts?

A: 

JTable is suited for this sort of task. you can do a lot of what you are looking for with renderers and editors. Here is a tutorial. An exerpt with my emphasis reads:

To choose the renderer that displays the cells in a column, a table first determines whether you specified a renderer for that particular column. If you did not, then the table invokes the table model's getColumnClass method, which gets the data type of the column's cells. Next, the table compares the column's data type with a list of data types for which cell renderers are registered. This list is initialized by the table, but you can add to it or change it. Currently, tables put the following types of data in the list:

  • Boolean — rendered with a check box.
  • Number — rendered by a right-aligned label.
  • Double, Float — same as Number, but the object-to-text translation is performed by a NumberFormat instance (using the default number format for the current locale).
  • Date — rendered by a label, with the object-to-text translation performed by a DateFormat instance (using a short style for the date and time).
  • ImageIcon, Icon — rendered by a centered label.
  • Object — rendered by a label that displays the object's string value.

Cell editors are chosen using a similar algorithm.

akf