?
Solved

Java JTable - Hold selected row.

Posted on 2007-03-26
5
Medium Priority
?
545 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

743 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