Ajay Patil
January 14th, 1999, 01:22 AM
Hi
I have got two tables say Usertable and Roletable .
The Usertable has two columns "UserName" & "RolesAttached" .
The RolesAttached column has a Checkbox component ie a boolean value and a
UserName has a TextField(String Value).
The Roletable has one column "RolesAvailable" which has a TextField component
associated with it.
My requirement is that when I click on of the roles in RoleTable and
then click on a username in UserTable then the RolesAttached checkbox
should be set to true value for that username.
Please explain me some way how it can be done.
Thanks in advance
Ajay
ariellopez
January 23rd, 2001, 10:29 AM
Can't you change the ui design? looks something unusual
Can you merge these two tables in just one?
dlorde
January 24th, 2001, 07:46 AM
I guess this means that when a UserName is selected you want it's associated RoleAttached entry ticked if there is a RoleAvailable already selected?
The problem I see is that there is no clear indication of which Role gets associated with the UserName - what happens if a UserName is selected then a Role? What happens if another UserName is then selected? Does it get linked with the Role selected for the previous UserName? Can the RolesAttached checkbox be unchecked manually? If so, this will count as selecting a UserName (it selects the same row by default) and the program will try to check the box again for you...
It can be done, but I would suggest a cleaner UI. Why not have a single table with a UserName text column and a Role column of dropdown combos. When you select a UserName you can then click on the Role dropdown in the next column, and select a Role. Then you can clearly see which Role is associated with the UserName (the first Role on the list should be 'None' or blank).
If you want to do it the way you said, add a ListSelectionListener to your UserTable to pick up the selected UserName row. In the ListSelectionListener.valueChanged() function call Roletable.getSelectedRow(). If it returns a value greater than -1 a row is selected, so you can tick your checkbox by setting the boolean value true for that item in your TableModel data, if it returns -1, set the value false. Then call AbstractTableModel.fireTableCellUpdated(row, column) to notify the UserTable to redisplay the checkbox.
This process doesn't keep a record of which Role associates with which UserName. If you want to do that, you'll have to keep a record of that separately. It also doesn't behave in a clear and unambiguous way.
I'd recommend a different UI, a single table, as I suggested above.
Dave
To email me remove '_spamjam' from my email address