Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Jtable row/cell/column selection issue

Thread view: 
apattin - 06 Apr 2006 02:07 GMT
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
hilizbabe@yahoo.com - 27 Apr 2006 22:50 GMT
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.
alejandrina - 28 Apr 2006 17:24 GMT
Yes, this did the trick. I was looking in the wrong places, like is
there a way to alter the selection modes...

Thanks!

Alejandrina


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.