/ Forside / Teknologi / Udvikling / Java / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Java
#NavnPoint
molokyle 3688
Klaudi 855
strarup 740
Forvirret 660
gøgeungen 500
Teil 373
Stouenberg 360
vnc 360
pmbruun 341
10  mccracken 320
JDialog Close operation på Esc
Fra : Janus


Dato : 19-04-06 14:12

Hej NG!

Kan man ikke få en JDialog til at reagere på KeyEvents? JDialog
returnerer i hvert fald true på isFocusable().
Jeg vil bare ha' min dialogboks til at lukke på et Esc-tryk.


Vh Janus

 
 
Mikael Flensborg (20-04-2006)
Kommentar
Fra : Mikael Flensborg


Dato : 20-04-06 08:11

Janus wrote:
> Hej NG!
>
> Kan man ikke få en JDialog til at reagere på KeyEvents? JDialog
> returnerer i hvert fald true på isFocusable().
> Jeg vil bare ha' min dialogboks til at lukke på et Esc-tryk.
>
>
> Vh Janus

Prøv at kalde denne routine fra et passende sted i din dialog

protected void mapEscape() {
InputMap map =
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
//Adding the key that needs to be captured
map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
ActionMap actionMap = getRootPane().getActionMap();
//Creating the action that needs to be executed when the key is
pressed
Action close = new AbstractAction() {
public void actionPerformed(ActionEvent ae) {
setVisible(false);
}
};
actionMap.put("cancel", close);
}

/Mikael

Søg
Reklame
Statistik
Spørgsmål : 177431
Tips : 31962
Nyheder : 719565
Indlæg : 6407952
Brugere : 218878

Månedens bedste
Årets bedste
Sidste års bedste