JTable - selected row in large table is not "visible"

Discussion in 'Java' started by Branko Kaucic, Oct 7, 2005.

  1. Hi all!

    I want to select row in JTable that contains large table (not all rows
    can be visible on the screen at once).
    I use method

    grid.getSelectionModel().setSelectionInterval(i,i);

    that selects the row that I wish (row i), but if this row is in
    "currently not shown part of table", table data is not scrolled (up or
    down) such that just selected row would be visible.
    What should I do, because this really bothers me:(

    Regards,
    B
    Branko Kaucic, Oct 7, 2005
    #1
    1. Advertising

  2. Repost: JTable - selected row in large table is not "visible"

    Hi!

    I still haven't found out this problem yet :(
    Have I missed the answer on news group? I hope not. If I am, I am sorry
    and please could you answer again.

    Thanks,
    B
    --
    Hi all!

    I want to select row in JTable that contains large table (not all rows
    can be visible on the screen at once).
    I use method

    grid.getSelectionModel().setSelectionInterval(i,i);

    that selects the row that I wish (row i), but if this row is in
    "currently not shown part of table", table data is not scrolled (up or
    down) such that just selected row would be visible.
    What should I do, because this really bothers me:(

    Regards,
    B
    Branko Kaucic, Oct 18, 2005
    #2
    1. Advertising

  3. Branko Kaucic

    zero Guest

    Re: Repost: JTable - selected row in large table is not "visible"

    Branko Kaucic <> wrote in
    news::

    > Hi!
    >
    > I still haven't found out this problem yet :(
    > Have I missed the answer on news group? I hope not. If I am, I am
    > sorry and please could you answer again.
    >
    > Thanks,
    > B
    > --
    > Hi all!
    >
    > I want to select row in JTable that contains large table (not all
    > rows can be visible on the screen at once).
    > I use method
    >
    > grid.getSelectionModel().setSelectionInterval(i,i);
    >
    > that selects the row that I wish (row i), but if this row is in
    > "currently not shown part of table", table data is not scrolled (up
    > or down) such that just selected row would be visible.
    > What should I do, because this really bothers me:(
    >
    > Regards,
    > B
    >


    This is very Swing dependent, so you may have better luck in either
    comp.lang.java.gui
    or Sun's own Swing Forum at
    http://forums.java.sun.com/forum.jspa?forumID=57

    I think what you need to do is:

    1. determine the height in pixels of one row in the JTable. There is a
    method for this in JTable if I'm not mistaken. 2. calculate the height
    in pixels of everything from the top of the table to the row that was
    selected - ie rows*height 3. scroll the JScrollPane down (or up as the
    case may be) to the selected row

    I haven't tested this, but I think it should work. I don't know of an
    easier way but there may be one. For that I refer you to the two
    references I gave above.

    Zero
    zero, Oct 18, 2005
    #3
  4. Branko Kaucic

    Roedy Green Guest

    Re: Repost: JTable - selected row in large table is not "visible"

    On Tue, 18 Oct 2005 13:26:25 +0200, Branko Kaucic
    <> wrote or quoted :

    > grid.getSelectionModel().setSelectionInterval(i,i)


    You just want to make sure those selected rows are as visible as
    possible, which might be impossible if the user has selected more than
    a screenful.

    You might want to simulate how the user would do it, first making the
    first row visible then the last.

    Keep in mind that your JTable lives in a JScrollPane. Perhaps someone
    will come up with a better, way, but you could use
    JScrollPane.getVerticalScrollBar().setValue().


    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Oct 19, 2005
    #4
  5. Branko Kaucic

    vivek Agnihotri

    Joined:
    May 26, 2008
    Messages:
    2
    Hi even i am facing the same problem.
    Can anyone help me out. The above solution did not work.
    I guess Branko Kaucic got the solution till now.
    Branko can you guide me to solve the issue.

    regards
    Vivek Agnihotri
    Last edited: May 26, 2008
    vivek Agnihotri, May 26, 2008
    #5
  6. Branko Kaucic

    vivek Agnihotri

    Joined:
    May 26, 2008
    Messages:
    2
    Page Up/Down is not working properly..

    Hi all!

    I want to select row in JTable that contains large table (not all rows
    can be visible on the screen at once).
    I use method

    table.changeSelection(selectedRow, selectedRow, false,true );

    that selects the row that I wish (row i), but if this row is in
    "currently not shown part of table", table data is not scrolled (up or
    down) such that just selected row would be visible.
    What should I do, because this really bothers me :(
    Please help me .. its urgent..
    vivek Agnihotri, May 26, 2008
    #6
  7. Branko Kaucic

    shadkam

    Joined:
    Dec 11, 2008
    Messages:
    1
    use table.scrollRectToVisible(table.getCellRect(row, column, false));
    Got it from: forumsDOTjavaDOTnet/jive/thread.jspa?messageID=312347
    shadkam, Dec 11, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandip Chitale
    Replies:
    1
    Views:
    1,032
  2. phl
    Replies:
    1
    Views:
    4,328
    Martin Jay
    Jun 8, 2006
  3. Jason
    Replies:
    1
    Views:
    2,290
    Alexey Smirnov
    Dec 14, 2009
  4. Selected Row Only GridView Row Visible?

    , Oct 17, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    280
  5. Jurjen de Groot
    Replies:
    0
    Views:
    293
    Jurjen de Groot
    May 19, 2008
Loading...

Share This Page