Please, help!

Hello, everybody!

I'm trying to have control over a key typed in a JTable. I want enable the

processing of this key only under certain circumstances. So I wrote this

code in the constructor of the JTable:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),"validar");

getActionMap().put("validar",

new AbstractAction()

{

privatestaticfinallong serialVersionUID = 3210268230549563142;

publicvoid actionPerformed(ActionEvent e)

{

if (/* some condition is true */)

{

// enable key

}

// do nothing

}

}

);

The problem is that I don't know what code of method call to write inside the

condition block to enable the key. I know that if I wasn't using a JTable, but

a JTextField, for example, I just would have to call thepostActionEvent

method on the JTextField, but this method doesn't exist on the JTable. So,

what code do I place there to enable the key?

Thank you.

Marcos

[1618 byte] By [Marcos_AntonioPSa] at [2007-11-26 22:17:19]
# 1

If I was using a JTextField instead of a JTable I would solve the problem with this code:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "validar");

getActionMap().put("validar",

new AbstractAction()

{

private static final long serialVersionUID = 3210268230549563142;

public void actionPerformed(ActionEvent e)

{

if (/* some condition is true */)

{

postActionEvent(); // this would solve the problem to me if I was using a JTextField

}

// do nothing

}

}

);

The postActionEvent method solves the problem with a JTextField. What do I use with a JTable?

Message was edited by:

Marcos_AntonioPS

Marcos_AntonioPSa at 2007-7-10 11:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 2
I have already posted this doubt in 'Java Programming' and I've got no answer there. Is really that hard?Marcos
Marcos_AntonioPSa at 2007-7-10 11:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 3

I'm sorry for my insistence on this, but I'm really stuck in my application with this problem. I can't proceed until I find a solution to this. I just want to enable/disable a key under certain condition in a JTable. The JTable component is only offering me the choice to disable a key, not enable. Why all the components don't reach like the JTextField, which has a postActionEvent method for this situation? This is a feature that we need not only in a JTextField component. In Delphi I could just write:

procedure TLogin.btnOkKeyPress(Sender: TObject; var Key: Char);

begin

if {condition ok} then

begin

// key will be precessed normally. Java don't let me do this

end

else

Key := #0; // ignore key. Java only let me do this

end;

Marcos

Marcos_AntonioPSa at 2007-7-10 11:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 4
I think all you need is to set a FLAG.boolean flag;if condition > flag = truecontinued here: http://forum.java.sun.com/thread.jspa?threadID=5150521&messageID=9564150#9564150
TuringPesta at 2007-7-10 11:11:14 > top of Java-index,Desktop,Core GUI APIs...
# 5
> I think all you need is to set a FLAG.> > boolean flag;> if condition > flag = trueIt doesn't work for me. The key would keep blocked by the ActionMap and I want it to be released after a condition holds.Marcos
Marcos_AntonioPSa at 2007-7-10 11:11:14 > top of Java-index,Desktop,Core GUI APIs...