1

I'd like some hints on how to address the following 2 issues (not the solution, I'd like to find that myself)

  1. how to create and maintain a JTable of which the number of columns and their widths is variable and configurable at runtime by the user. I tried already some things and manage to do this on creation of the form (with tablemodel) but I prefer to be able to do this also when the form is already displayed.

  2. once that's out of the way, I want to have a JPanel on top of the table with JTextFields that mimics the table's columns. I've not found a layout that permits me to create the textfields with different widths and on the correct positions... although FlowLayout seemed to be most promising. Again, if table layout changes the textfields should change as well.

joce
  • 9,624
  • 19
  • 56
  • 74
dsmalle
  • 11
  • 2
  • Please clarify point 2. Does the panel field need to be "on top"/"over" the actual table, or laid out in the parent container so it appears above the table? Column widths can be also be maintained by the user simply by allowing them to resize the columns with the mouse. – MadProgrammer Mar 14 '13 at 21:40
  • For point 1, the `JXTable` from the SwingX project has already a built-in UI – Robin Mar 14 '13 at 23:45
  • For point 2: indeed the panel should be on top of the table, no overlap. And if the users change columns width, the textfield width will change as well. – dsmalle Mar 18 '13 at 07:49
  • The JXTable seems very promising: the column selection is covered by the "visible" property. I'll try it. – dsmalle Mar 18 '13 at 07:59

1 Answers1

2

For point 2, if I understand correctly, you might want to consider a single row table. If you don't put it in a JScrollPane, you won't get the headers, which is what I think you want.

You could then put a TableColumnModelListener on the main table's TableColumnModel, so that you could pick up when the user resizes the columns, and adjust the column widths of the single-row table accordingly.

splungebob
  • 5,357
  • 2
  • 22
  • 45