Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Another JTable Navigation Question  RSS feed

 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
If a column in a "JTable" has zero width, it is not visible,
as demonstrated in below code snippet:

However, when using the keyboard navigation keys, like TAB, to navigate
the "JTable" cells, the invisible cell still receives the focus.
When an invisible cell has the focus, there is no visual indication of this
and the user has no idea why suddenly no cell of the table is selected.
My question is: What is a recommended way of ensuring that invisible columns
in a "JTable" do not receive input focus?

Thanks,
Avi.
[ November 04, 2008: Message edited by: Avi Abrami ]
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Avi Abrami:

My question is: What is a recommended way of ensuring that invisible columns
in a "JTable" do not receive input focus?
[ November 04, 2008: Message edited by: Avi Abrami ]


Remove the column instead of hiding it by making it 0 width.
In case you do not know how to remove columns, search the forums. There are quite a few recent threads which will tell you how to do it.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh,
You said:

Remove the column instead of hiding it by making it 0 width.

Oops, forgot to mention the obvious (to me, anyway :-)
This is not my application, I am just maintaining it.
At this stage, the invisible columns are required and used by the application so removing them is not currently an option.
Hence the question ;-)
Thanks anyway for your prompt and nonetheless helpful reply.

Cheers,
Avi.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try tracking the focus.
If your "undesired" column gains focus, you can shift the focus on the previous/next column.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh,
Thanks again for your help.
Please pardon my ignorance, but how does one "track the focus"?
I assume I need to add a focus listener, or is there another way?
Method "addFocusListener" is defined in class java.awt.Component.
So which "Component" should I add the focus listener to, since "JTable" is a complex GUI control that involves many different "Component"s.

Also, there appears to be several ways to "shift the focus".
I am hoping that someone reading this will be able to recommend a preferred way of doing this.

Thanks,
Avi.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you aware of the "Renderer" concept? Usually you define a Renderer for a Column.
The getTableCellRendererComponent() method returns a Component.
So one of the possible ways is to add a focus listener to the renderer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!