CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 1999
    Posts
    2

    Communication between two JTables



    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



  2. #2
    Join Date
    Jan 2001
    Location
    Argentina
    Posts
    5

    Re: Communication between two JTables

    Can't you change the ui design? looks something unusual
    Can you merge these two tables in just one?



  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Communication between two JTables

    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
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured