Re: ListSelectionModel problem



danharrisandrews@xxxxxxxxx wrote:
Deniz Dogan wrote:
Code follows:

public void keyPressed(KeyEvent e) {
[...]
//selmodel is the ListSelectionModel of the JTable.
//mod is the String representation of the modifier keys pressed.
//table is the JTable.
else if ((mod.equals("Shift") || mod.equals("Ctrl")) && e.getKeyCode()
== KeyEvent.VK_ENTER) {

Hi Deniz:

Try something like this (see below). Also google for "For example, the
appropriate way to check that SHIFT and BUTTON1" and check the javadocs
for getModifiersEx.

int shiftMask = InputEvent.SHIFT_DOWN_MASK;
int ctrlMask = InputEvent.CTRL_DOWN_MASK;
int selectedrow = table.getSelectedRow();
if (selectedrow != -1) {
if ((e.getModifiersEx() & (shiftMask | ctrlMask)) == shiftMask) {
System.out.println("Shift");
} else if ((e.getModifiersEx() & (shiftMask | ctrlMask)) ==
ctrlMask) {
System.out.println("Ctrl");
}
}

Thank you for the tip, Dan! I shall try it out!

And as for the actual problem I was having, I've found out that I had actually programmed the program to do a whole other thing than what I really wanted! It's not the table itself that should listen for the keys, it's a couple of text boxes that show specific information _from_ the table. Hence, problem solved! :-)

Thanks a lot to you both of you guys for the help, I appreciate it!
.


Quantcast