Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java JTable - Hold selected row.

Posted on 2007-03-26
5
Medium Priority
?
547 Views
Last Modified: 2010-08-05
Hi all,

I'm looking for help with a JTable issue in Java.

I have a read only table which displays rows of info with multiple columns.

When an operator selects a row in the table the selected row is highlighted.

I have written an event handler to say if the operator presses the enter/return button following selection of a row in my table, a secondary dialog is popped up.

All fine up to here........

I cannot find a way to disable the JTable from moving the currently selected row to the next row down in the table following the enter/return button being pressed on a selection in the table.

If anyone knows how to stop the currently selected row from shifting down it would be greatly appreciated.
0
Comment
Question by:Zuzic
[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
  • 2
  • 2
5 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18797942
You mean the row itself is being dragged down?
0
 

Author Comment

by:Zuzic
ID: 18798133
No, the row sizes do not change shape nor size.

I'm seeing the highlighting of row that I mouse clicked on and then pressed enter on shift down to the next row in the table.

e.g.

Table contains 3 rows with first name and surname colums filled in with:

Joe Bloggs
Jill Smith
Paul Emersons

I select Joe Bloggs with the mouse and that row is highlighted in the table.

I now press the enter button on the keyboard and my program brings us another dialog related to Joe Bloggs.

Observing my table I now see Jill Smith being highlighted because I pressed the enter button on the keyboard.

I'd like to see Joe Bloggs still highlighted at this point.
0
 
LVL 10

Accepted Solution

by:
ADSLMark earned 1000 total points
ID: 18798393
You can consume() an event. So you get sth like:

class MyKeyListener
    extends KeyAdapter
{
    public void keyPressed(KeyEvent ke)
    {
         // open dialog
        ke.consume();
    }
}

Mark
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18800314
Yes, you can check for the key being the Enter key before that:

jTable.addKeyListener ( new KeyAdapter () {
    public void keyPressed ( KeyEvent ke )
    {
      if ( key.getKeyCode () == KeyEvent.VK_ENTER )
      {
         // open dialog
         ke.consume () ;
      } // end if

    }

} ) ;
0
 

Author Comment

by:Zuzic
ID: 18804570
It was the consume() call which I was after here in order to stop any calls being carried out behind the scenes against the JTable when the ENTER button is pressed on it.

Thanks for all input.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

618 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