• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Selective ui cell selection swing jtable

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am having a table of 4 columns. While tabbing through, i want the columns 3,4 are to be selected and not the 1,2. How to do that?
Right now, i put the code in isCellEditable() method

but 1,2 column gets focus then transfer happens. Any solution for avoiding the 1,2 column tab movement.
thanx in advance.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think if you try to find out which column is selected using table.getSelectedColumn() & then if you are able to find out if its 1st or 2nd column then setfocus to the next column.
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, this seemingly simple question requires a complex solution. I'll try to express clearly and succinctly.
The answer in short is that you should use different TableCellRenderer for each of your 4 columns.
javax.swing.JTable has a method:
void setDefaultRenderer(Class columnClass, TableCellRenderer cellRenderer)
As for the columnClass, you choose the argument according to the class type of data you intend to put in the cells of each of the 4 columns, such as Color.class.
As for cellRenderer, you should use javax.swing.table.DefaultTableCellRenderer, which extends from JLabel, which in turn extends from JComponent.
Well, JComponent has two methods we'll use here:
public boolean hasFocus()
public void setNextFocusableComponent(Component aComopnent)
When you set default cellrenderer for column 1 and 2, override the hasFocus() method by always returning false.
When you set default cellrenderer for column 3 and 4, override the hasFocus() method by always returning true and override the setNextFocusableComponent(Component aComopnent) method by returning the next cell you want to focus next.
I haven't tried this solution yet. If you encounter any problem, please post it immediately.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anuma,

Please re-register with a name that follows the JavaRanch Username Convention. User names are requires to be in the format "First name" + space + "Last Name".

Thanks,
-Nate
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
It doesn't work out. The hasfocus and nextfocusable component overriding is having absolutely the same effect.
Any other clue to restrict the navigation in table for the selective columns alone? Is there any range set option.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic