Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Jtable row/cell/column selection issue

Reply
Thread Tools

Jtable row/cell/column selection issue

 
 
apattin
Guest
Posts: n/a
 
      04-06-2006
Hi all,

I think we're tied in our underwear here...

(a) My JTable is set to allow cell selection, so I have these
statements when I set up the table:

fpeTable.setRowSelectionAllowed(false);
fpeTable.setColumnSelectionAllowed(false);
fpeTable.setCellSelectionEnabled(true);

things work as advertised.

(b) I also have a mouse listener for column header clicks that
programatically selects all the cells in the column. The cells are
shown with a different background, as wanted.

(c) Now I would like to simulate the effect of
setRowSelectionAllowed(true) in that I'd like to color all the row when
any cell is clicked (selected). So I created a custom renderer that
sets the background of the JLabel component to a different color when a
cell is selected. This works too. However, now if I click on the column
header, the entire table's background is changed. Clearly not what I
want, and I understand why it's happening (because of the custom
renderer sees all cells in the column being selected by the mouse
listener).

How does one fix this? The behavior we want is:

If a cell is selected via a click, simulate selection with the custom
renderer; however, if the cells are selected from the column header
click, just select the column. Can this be done?

Thanks!

Alejandrina

 
Reply With Quote
 
 
 
 
hilizbabe@yahoo.com
Guest
Posts: n/a
 
      04-27-2006
get the click x,y location and use the JTable columnAtPoint(Point
point) or rowAtPoint(Point point) methods to check whether the click
was done within the table. If the click is outside the table, the
above methods will return -1.

If it is outside, do not do the default select all columns in a row
logic

--------------
QuickTable - A free javabean grid control on top of JTable which hides
all complexities of JTable
http://quicktable.org.

 
Reply With Quote
 
 
 
 
alejandrina
Guest
Posts: n/a
 
      04-28-2006
Yes, this did the trick. I was looking in the wrong places, like is
there a way to alter the selection modes...

Thanks!

Alejandrina

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
JTable with row selection, but no cell selection Simon Niederberger Java 2 01-07-2005 04:17 PM
JTable, fireTableDataChanged, selection Nosnos Java 1 11-11-2003 09:02 AM
JTable cell selection event Don Java 4 10-30-2003 09:58 AM



Advertisments