Click to See Complete Forum and Search --> : Dynamic GridLayout vs Table?!?


Tom Gone
October 11th, 1999, 11:48 AM
Hiya (again I guess :),

I have another little "problem" which I'm looking for pointers to. Basically what I want to do is to create a dataentry window which is created by another window. The first window asks the user how many data items they want to enter (for example 2 persons and 4 items), this then creates the second window which then has a corresponding layout. In the example here, I would want something like this

Item Person1 Person2
#1 JTextField JTextField
#2 JTextField JTextField
#3 JTextField JTextField
#4 JTextField JTextField

where the titles, and the #1 etc are all JLabels. I can do the first window no problems, and I can do this second window as well. However my problem is that as I create the JTextFields dynamically I cant give them names, so I dont know how to access the information in them?!? In theory I could end up with any number of columns * any number of rows.

I am just implementing it using a JTable, but dont like that solution very much. Any idea of 1. which is the better way to do it (the labels etc should not be changeable) and 2. how can you get at the text in the JTextField if implemented as I proposed above?

I have played with using Vectors for the JTextFields etc, but its a very clumpsy solution.

Cheers as always for any pointers
Thomas

unicman
October 17th, 1999, 01:04 AM
I didn't understand why u don't want JTable?

1. If u can have columns * items textfields i.e. cells, u can store/retrieve them from TableModel easily. Just use 'getValueAt' method.

2. If u want some cells shouldn't be editable, u can return 'isEditable' false in the TableModel.

I think JTable is good on the basis of ur last post. If the problem is different, please tell me.

- UnicMan
http://members.tripod.com/unicman

Tom Gone
October 18th, 1999, 11:28 AM
Hiya,

Cheers for the response. I have no problems getting the JTable layout I want, nor getting the values from the JTable. What I dont like about the JTable though is that I would prefer to have JLabels etc.

I just had a look at the API and cant find the isEditable field anywhere? There is an isEditing, but this returns true/false if the cells in question is currently being edited. Could you please explain what you ment by the isEditable?!?

Cheers
TG

unicman
October 20th, 1999, 10:19 PM
I'm sorry its 'isCellEditable'. This method is in TableModel which should return whether the specified cell is editable.

Execuse me if I haven't got ur problem. But if u want a column (or a cell) to be a JLabel, u can have cell renderer which returns either JLabel or whatever u want.


- UnicMan
http://members.tripod.com/unicman

Tom Gone
October 25th, 1999, 04:43 AM
Hiya,

>I'm sorry its 'isCellEditable'. This method is in TableModel which should return whether the specified cell >is editable.

I thought you could only use this to find out if a cell was editable, and I must say it was confusing to find that there was a method to find if a cells is editable, but not one to set editable for a cell :)

> Execuse me if I haven't got ur problem. But if u want a column (or a cell) to be a JLabel, u can have cell > renderer which returns either JLabel or whatever u want.

I have found an example somewhere now that does exactly this. A little more complicated than I thought, but I think I might be on the right track!

Cheers for your help
Thomas