This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes getting focus in one cell in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting focus in one cell in JTable" Watch "getting focus in one cell in JTable" New topic
Author

getting focus in one cell in JTable

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255


My JTable is already set up for selecting a single cell at a time. I would like to know what command to use to get the cell at (selectedRow, selectedColumn) to have focus, too, not just selection. I assume I should get the component of the cell and do .requestFocus()
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

There's no 'component of the cell'. Are you looking for editCellAt(...) ?


luck, db
There are no new questions, but there may be new answers.
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255


The way my program is so far, the program selects a single cell, but when the user starts typing something, what the user typed does not enter the cell. What I want is to have the program make the cell so that the border of the cell changes color and when the user types something, it enters the cell.
Basically what I want is, what happens when the user clicks a cell once, except that I want the program to do it so that the user does not have to.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
What I want is to have the program make the cell so that the border of the cell changes color and when the user types something, it enters the cell.


This happens by default when you use the DefaultTableModel since by default all cells are editable. Post your SSCCE that demonstrates the problem.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
is there something that triggers the posted code?

a JButton? if so, make the button not focusable
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Thank you. I just added this line:

and it seems to work okay now. I get it now. Just request focus for the table, and whatever cell is selected will be ready to edit (if the cell is editable).
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Read the API for requestFocus(), it's recommended that you use requestFocusInWindow() instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting focus in one cell in JTable
 
Similar Threads
JTable/Column modification /urgent
JTable
JTable
lost focus in JTable
JTable Columns