Mnemonics for TextField, Label, Combox

Hi, Please advise me how to add Mnomonics for TextField, Label, Combox.Thanks a lot in advance.Rama Reddy.
[141 byte] By [ramareddys] at [2007-9-26 2:38:43]
# 1
What do you mean my a 'Mnemonic'?
AnyoneEB at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 2
just to clarify, do you mean setting an (in win32) underscore under an item name, and then when you press alt and that letter it recieves focus?
glicious at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 3
are u talking about Mnemonics in Menu'si.e Using shortcuts method with Keyboard actionisn't it u want.clarify me
Rama at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 4
I mean Using shortcuts method with Keyboard action.
ramareddys at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 5
so you want it so you press say Alt-T and the focus is set at Textbox labeled Alt-T? Well, I know you can use KeyListener to trigger when you press Alt-T... one sec I think I know I'll edit with the code!
AnyoneEB at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 6
Sorry, all that text fields have about Focus is boolean gotFocus and nextFocus, I don't know what nextFocus is so I can't help you, maybe someone else does.
AnyoneEB at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 7

Did it! here's the code of an Applet, all it does is show a textfield and when you press Alt(but no Ctrl)-t it will switch the focus to the TextField:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

public class test extends Applet implements KeyListener

{

public TextField tF=new TextField();

public void init()

{

add(tF);

this.addKeyListener(this);

}

public void keyTyped(KeyEvent ke) {}

public void keyPressed(KeyEvent ke)

{

if((ke.getKeyChar=='t' || ke.getKeyChar=='t') && ke.isAltDown && !ke.isControlDown)

tF.requestFocus();

}

public void keyReleased(KeyEvent ke) {}

}

AnyoneEB at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 8
if(ke. isControlDown())<<-- the missing part, for checking if CTRL or Control is pressed...SanderTheFellowShipOfTheRing@hotmail.com
SanderSander at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 9

You need to recursivly add a keylistener to all of the components, (and update it romving/adding) when components are added/removed set invisible/visible...)

this keylistener could contain a map of all components that has a shortcut key linkt to it. It then calls requestFocus() on the that component when the spesific key is hit. Then you need some graphics overriding to display the components, and maybe some handeling of multiple equal shortcuts...

A lot of work?

yes, but it works (done it myself) and its reusable.

";-)

Ragnvald Barth

Software engineer

Ragnvald at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 10
I am sorry. I have Solved this.
ramareddys at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...
# 11
Add keyListener for this and listen for these keys.Add setFocus to the component.Hope this solves.
javadev9r at 2007-6-29 10:10:02 > top of Java-index,Desktop,Core GUI APIs...