Criar Atalho!

Como crio um atalho para um JMenuItem… por exemplo pro Item Abrir colocar o atalho CTRL+O, Copiar CTRL+C, etc…

e aproveitando o tópico…

alguém pode postar um código pra abrir um arquivo qlqr…e futuramente colocar o arquivo num JTEXTAREA ou JEditorPane???

já olhei alguns exemplos mas naum consegui entender…

Muito Obrigado Galera

cara, atalho eu não sei, mas vc pode usar minemonicos… por ex:

JMenuItem aboutItem = new JMenuItem( "Sobre..." ); aboutItem.setMnemonic( 'S' );

…vai criar um JMenuItem com o label “Sobre…” … e o ‘S’ vai estar sublinhado, ou seja… qnd vc apertar a letra ‘s’ no teclado, ja vai executar o aboutItem…

…e sobre o arquivo, de uma olhada no FAQ… com certeza vc se acha…

http://www.portaljava.com/home/modules.php?name=Encyclopedia&op=terms&eid=12<r=

esse eu sei… mas eu queria atalho tipo CTRL + (alguma letra)

igual a todos os programas tem… Word por exemplo… pra abrir é CTRL+A, PotoShop é CTRL+O…

naum tem como fazer isso???

bem, vc pode usar um keyListener nesse caso então… ai chama o método apropriado do menu… veja este código, creio q vc vai entender:

[code]import java.awt.;
import java.awt.event.
;
import javax.swing.*;

public class KeyDemo extends JFrame implements KeyListener {

private String line1 = "", line2 = "";
private String line3 = "";
private JTextArea textArea;

public KeyDemo()
{
super( "Demonstrating Keystroke Events" );

  textArea = new JTextArea&#40; 10, 15 &#41;;
  textArea.setText&#40; &quot;Pressione qualquer tecla...&quot; &#41;;
  textArea.setEnabled&#40; false &#41;;
  getContentPane&#40;&#41;.add&#40; textArea &#41;;

  addKeyListener&#40; this &#41;;

  setSize&#40; 350, 100 &#41;;
  setVisible&#40; true &#41;;

}

public void keyPressed( KeyEvent e )
{
line1 = "Key Pressed: " + e.getKeyText( e.getKeyCode() );
setLines2and3( e );
}

public void keyReleased( KeyEvent e )
{
line1 = "Key Released: " + e.getKeyText( e.getKeyCode() );
setLines2and3( e );
}

public void keyTyped( KeyEvent e )
{
line1 = "Key Typed: " + e.getKeyChar();
setLines2and3( e );
}

private void setLines2and3( KeyEvent e )
{
line2 = "This key is " +
( e.isActionKey() ? "" : "not " ) +
"ahn action key";

  String tmp = e.getKeyModifiersText&#40; e.getModifiers&#40;&#41; &#41;;

  line3 = &quot;Modifier keys pressed &quot; +
     &#40; tmp.equals&#40; &quot;&quot; &#41; ? &quot;none&quot; &#58; tmp &#41;;

  textArea.setText&#40; line1 + &quot;\n&quot; + line2 + &quot;\n&quot; + line3 + &quot;\n&quot; &#41;;

}

public static void main( String args[] )
{
KeyDemo win = new KeyDemo();

  win.setDefaultCloseOperation&#40; JFrame.EXIT_ON_CLOSE &#41;;

}

}[/code]