File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Set focus on JTable with no rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Set focus on JTable with no rows" Watch "Set focus on JTable with no rows" New topic
Author

Set focus on JTable with no rows

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hi friends, sir, madam

I want to set the focus on JTable with no rows. Generally when any component receives the focus I set a blue border around the component. The same thing I want to apply for JTable. By pressing the tab button i.e by doing focus traversal, when JTable with no rows receives the focus then blue border is set around the JTable. However when I explictly click on JTable with no rows then the blue border is not drawn. What I observed is when I added focus listener and mouse listener to JTable, even the call back methods werent called when I click on JTable with no rows. Can anyone help how can I set the blue border on JTable with no rows.

Waiting for your reply.

Thanks and Regards
Rohit.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
even the call back methods werent called
The table consumes mouse and focus events because it has (behind the scenes) MouseListeners that are listening for user selections and FocusListeners that are listening for focus changes.
Can anyone help...
Add a MouseListener to the JTable and listen for mouse events in the mouseClicked method to set your blue border. Adding your own listeners is an accepted way of customizing JTable to your needs.
 
Don't get me started about those stupid light bulbs.
 
subject: Set focus on JTable with no rows