JTable Selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 123456prakash
    New Member
    • Jan 2007
    • 35

    #1

    JTable Selection

    I have a problem with JTable Selection


    I have a table which allows multiple selection it has only
    ONE column with string values
    I have 10 rows

    I selected rows 2,5,7. And i saved these values

    But when i again load the table
    I am not able to make the selection of these row only the last row is selected
    ie only 7th row

    mycode is something like this

    StringTokenizer rowsValue = // in this i get the values ie 2,5,7 row

    jTableX1.clearS election();

    while (rowsValue .hasMoreElement s()) {

    String name = rowsValue.nextE lement().toStri ng().trim();

    for (int i = 0; i < rowcount ; i++) {

    String temp = jTableX1.getVal ueAt(i, 1).toString().t rim();

    if (temp.equalsIgn oreCase(sensor) ) {
    jTableX1.setRow SelectionInterv al(i,i);
    }

    }

    Is this code correct can anyone help out
    prakash
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by 123456prakash
    I have a problem with JTable Selection


    I have a table which allows multiple selection it has only
    ONE column with string values
    I have 10 rows

    I selected rows 2,5,7. And i saved these values

    But when i again load the table
    I am not able to make the selection of these row only the last row is selected
    ie only 7th row

    mycode is something like this

    StringTokenizer rowsValue = // in this i get the values ie 2,5,7 row

    jTableX1.clearS election();

    while (rowsValue .hasMoreElement s()) {

    String name = rowsValue.nextE lement().toStri ng().trim();

    for (int i = 0; i < rowcount ; i++) {

    String temp = jTableX1.getVal ueAt(i, 1).toString().t rim();

    if (temp.equalsIgn oreCase(sensor) ) {
    jTableX1.setRow SelectionInterv al(i,i);
    }

    }

    Is this code correct can anyone help out
    prakash
    Sorry I'm not really understanding your problem. You said you can select and save the first time . But when you try to select again what is happening?

    Comment

    • 123456prakash
      New Member
      • Jan 2007
      • 35

      #3
      Originally posted by r035198x
      Sorry I'm not really understanding your problem. You said you can select and save the first time . But when you try to select again what is happening?

      Actullay i can select and save every time . But i m not able to load the selected value programtically. for example i have 10 value like

      aaa
      bbb
      ccc
      ddd
      eee
      fff
      ggg
      hhh
      iii
      jjj


      i selected ccc and ggg . so it gets highligthed ... and saved these values
      Now the selection is removed or selected some other value say aaa .

      So now on some button click i want to load the selected value only
      that is only ccc and ggg should be highligthed

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by 123456prakash
        Actullay i can select and save every time . But i m not able to load the selected value programtically. for example i have 10 value like

        aaa
        bbb
        ccc
        ddd
        eee
        fff
        ggg
        hhh
        iii
        jjj


        i selected ccc and ggg . so it gets highligthed ... and saved these values
        Now the selection is removed or selected some other value say aaa .

        So now on some button click i want to load the selected value only
        that is only ccc and ggg should be highligthed
        You now want to load only ccc and ggg with aaa highlighted?
        I must be very dumb today. I'm still failing to grasp what you are saying.

        Comment

        • 123456prakash
          New Member
          • Jan 2007
          • 35

          #5
          Originally posted by r035198x
          You now want to load only ccc and ggg with aaa highlighted?
          I must be very dumb today. I'm still failing to grasp what you are saying.
          No mate i want all the 10 values to be loaded but with only ccc and ggg highlighted because i selected them and saved those values
          hope u got me

          Actullay when we select any value in a JTable using mouse it gets highligthed or color changes . The selected rows look different from un selected rows

          So since i saved those to selected rows . i need to load ie i want to highlight the selected rows on some buton click without mouse

          Comment

          Working...