Solved

JTable row select

Posted on 2009-04-10
4
3,023 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

707 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