Solved

JTable row select

Posted on 2009-04-10
4
3,021 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to become programmer? 12 38
JTable - Group/UnGroup/Drag&Drop 2 93
What is an NDK ? 3 100
Debugging a PHP Web Application 2 106
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 use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 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