aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes how to disable highlight going to the next row when you press enter in jtable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "how to disable highlight going to the next row when you press enter in jtable." Watch "how to disable highlight going to the next row when you press enter in jtable." New topic
Author

how to disable highlight going to the next row when you press enter in jtable.

martin naughton
Ranch Hand

Joined: Sep 09, 2009
Posts: 30

Hello Guys,
I have searched the internet for a while and have not found a definite answer to this.

In my URLybird implementation i am only allow the user to book a room. they will not be able to unbook the room. The way i want the user to book the room is this way:

click on the owner cell to enter the information
enter the information and press enter
click on the book button and the booking is disabled on the room.

The only problem is when i press enter the highlight on the jtable goes to the next line. Then when i press book it will book the wrong room because the highlight has gone down the row one.

This is the only way so far i have come up with the solution myself to stop the highlight going to the next row.


The table.getCellEditor().stopCellEditing(); will enter the information into the jtable so i can get it to send to the data and consume will consume the action where it goes to the next row.

Is there any other way i could stop the highlight going to the next line. i want to stay on the same row so when i click book it will get the information on that row. Also looks good when the user click book that they are clicking book on the correct row.

thanks for any help

martin


SCJA Done
SCJP Done
SCJD URLybird 1.3.1 Passed
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

martin naughton wrote:...
click on the owner cell to enter the information
enter the information and press enter
click on the book button and the booking is disabled on the room.
...
The only problem is when i press enter the highlight on the jtable goes to the next line. Then when i press book it will book the wrong room because the highlight has gone down the row one.
...
Is there any other way i could stop the highlight going to the next line. i want to stay on the same row so when i click book it will get the information on that row.

Since booking a room is the only reason to enter the information, why should this be a two-step process? Isn't the booking process really over when the user presses "enter"?


OCMJD 6, OCPJP7, Baroque Potion, G+
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

If you decide to have an editable JTable and enter the customer id, I would guess the room gets booked when pressing "Enter", having to click another button seems quiet weird to me. If you decide to use a seperate dialog/panel, you'll select the room, hit the "book" button, dialog/panel is shown, user provides the necessary information and confirms the dialog/panel and the room is booked. I implemented the dialog/panel approach, because it's easier to have this approach (and extend it in the future) than creating a fully editable JTable (Swing is not always your friend )


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
 
subject: how to disable highlight going to the next row when you press enter in jtable.