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( 10, 15 );
textArea.setText( "Pressione qualquer tecla..." );
textArea.setEnabled( false );
getContentPane().add( textArea );
addKeyListener( this );
setSize( 350, 100 );
setVisible( true );
}
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( e.getModifiers() );
line3 = "Modifier keys pressed " +
( tmp.equals( "" ) ? "none" : tmp );
textArea.setText( line1 + "\n" + line2 + "\n" + line3 + "\n" );
}
public static void main( String args[] )
{
KeyDemo win = new KeyDemo();
win.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}[/code]