?
Solved

JTable row select

Posted on 2009-04-10
4
Medium Priority
?
3,028 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 375 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deletiā€¦
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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