Solved

JTable row select

Posted on 2009-04-10
4
3,019 Views
Last Modified: 2013-11-23
How do I get a row in JTable selected when user clicks on first column in that row?

Rest of the time I want user to be able to block individual or group of cells so I have:

myTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
myTable.setCellSelectionEnabled(true);
0
Comment
Question by:John4343
  • 3
4 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 24135665
>> Rest of the time I want user to be able to block individual or group of cells so I have:
What do you mean with block?
I don't know if I understand you well, but if you *don't* want users to be able to select individual cells, you should have

myTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);  // = selected rows shouldn't be consecutive
myTable.setCellSelectionEnabled(false);  // false instead of true = you can't select individual cells

Then clicking in whatever column of a row, selects automatically the whole row.
Is that what you want?
0
 

Author Comment

by:John4343
ID: 24184138
Sorry for lack of clarity (and delay is response).

I want user to be able to select an individual cell or a block of cells by clicking and draging across a rectangular block of contiguos cells.  In addition select a single row.  For row selection I thought I could put a select arrow in the first column which, when clicked, would select the complete row.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 125 total points
ID: 24184261
Then you have to add a mouselistener on the table and listen for mouse click and mouse release

The mouseevent has a point and with that one you can get the row and the column of the start/end of the drag:

JTable has the methods:
columnAtPoint(Point point)
rowAtPoint(Point point)

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24335736
thanx 4 axxepting
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now