• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable responding to row clicks  RSS feed

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm building a Swing application that's basically a specialized database. (There's a new one.) The main interface is going to look a lot like a spreadsheet (another first), with rows of records and columns of fields.

I'm guessing that this component should be a JTable, but since I'm not experienced in Swing, I'm hoping to get some confirmation and/or guidance on this.

I realize that users can edit data directly in JTable cells, but can users "open" a record in a new window by double-clicking on a row? Specifically, can a JTable be made to respond to clicks like this?

Here's a simple illustration. The table might display only a few fields, like this...

But clicking on a specific line would bring up a new frame with more complete information on that record, like this...

NAME: J. Garofalo
ADDRESS: 999 SomeStreet
CITY: Metropolis
STATE: QQ
ZIP: 99999
PHONE: 999-999-9999 ext. 3
FAVORITE COLOR: Plaid
SHOE SIZE: 8
BEVERAGE OF CHOICE: Latte (24 oz.)

I found the following post from 2003, which looks like it's close. But is this the best approach, or is there something entirely different I should look at?

http://www.coderanch.com/t/337083/GUI/java/JTable-cell-listening-mouseClicked
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a situation where it's possible for the user to double click a row without selecting that row? What I'm getting at is that if you're guaranteed to have the row selected for the frame you want opened at thetime of the click then you can do this:



It has worked fine in the instances where I've needed to do something based upon a double click of a row. Let me know if this won't work for you, it's not hard to calculate the row at the point clicked.
[ October 25, 2005: Message edited by: Ken Blair ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ken: I think that might work for me. I'm still a few days from tackling this part of the code, so I'm basically gathering information now -- trying to make sure I'm not totally off base in my thinking.

I'll let you know how this works when I get there. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!