File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes anchor cell return -1 for row and column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "anchor cell return -1 for row and column" Watch "anchor cell return -1 for row and column" New topic
Author

anchor cell return -1 for row and column

harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
hi all,
when i get focus on the anchor cell of my JTable , it returns -1 value for both row and column, and when i move it forward to the next cell in this row ,only then it selects the this row, i wanted to select this row when the anchor cell has the focus.need some help here
thanks
harcharan
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi harcharan,
What do you mean by the term anchor cell?
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
that is the first cell in JTable at position 0,0,where i get the focus with my tab key ,and at this point on , i like to select this row, but this does not happen untill i move the focus to the next cell at 0,1(row,column),i could not find in api anything like selectrow(int row),i found
isRowSelected();
setRowSelectedAllowed(true);
and i am also working with
getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus,
int row, int column)
I am trying to select the first row ,when the focus is at cell number 0,0.Am i missing anything,or any advice will be valuable.
thanks

thanks
harcharan
[ September 26, 2002: Message edited by: harcharan kanwal ]
[ September 26, 2002: Message edited by: harcharan kanwal ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi harcharan,
Give us some more details on what you want to do here. Is your JTable editable, are you using a ListSelectionListener, etc.? Without a little more info we can't try any sample code.
You may try something like this:

Michael Morris
[ September 26, 2002: Message edited by: Michael Morris ]
harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
hi Michael,
i want to select a row and pop up a book dialog with this flight info using key board operation,ofcourse evreything works fine with the mouse click,my table cells are not editable,and i am not using
ListSelectionListener.is that something i have to work ,
thanks for taking me through
harcharan
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi harcharan,
Are you using the TAB key to acquire the focus? For an uneditable JTable the behavior seems to be that upon gaining the focus, nothing is selected. On the next TAB, a selection occurs. You could try something like this in your JTable (assuming you are extending JTable):

Let me say that I have no idea as to whether this is going to work or not, but it's worth a shot.
Hope this helps,
Michael Morris
harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
he michael,
i got this problem solved with this
table.setRowSelectionInterval(row, row),i can think ahead from here.
thanks for your help
harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
hi Michael,
is it ok to tell the user to use the tab key to move the focus around on components in a container
or do we have to write mnemonics .
thanks for help
harcharan
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Harcharan,

is it ok to tell the user to use the tab key to move the focus around on components in a container

That's fine. No need to use mnemonincs. It's always better to use the default behavior if you can. CTRL+TAB is actually what is required when using a JTable, because when the JTable gets the focus, TABs move from cell to cell in the table.
Michael Morris
harcharan kanwal
Ranch Hand

Joined: Jul 02, 2001
Posts: 64
hi Michael,
yes ctrl+tab is helpful to get the focus out from jtable to container one before the where jtable is displayed.
thanks for help
harcharan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: anchor cell return -1 for row and column