Problema com tecla de atalho[Resolvido]

5 respostas
Schoker

Bom dia!

Eu estou tentando criar uma tecla de atalho...mas da o seguinte erro:

java.lang.NullPointerException
at br.com.mrsautomacao.gui.PainelFinanceiro.initGUI(PainelFinanceiro.java:1242)
at br.com.mrsautomacao.gui.PainelFinanceiro.(PainelFinanceiro.java:194)
at br.com.mrsautomacao.gui.DialogServico.(DialogServico.java:557)
at br.com.mrsautomacao.gui.PainelServico$1.actionPerformed(PainelServico.java:67)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

segue o codigo:

pressF1 = new AbstractAction("F1"){
					public void actionPerformed(ActionEvent e) {
						JOptionPane.showMessageDialog(null, "Dinheiro");
					}
				};
			
				int cond = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
				KeyStroke f1 = KeyStroke.getKeyStroke(KeyEvent.VK_F1,0);
				
				//GUARDA O ROOTPANE 
				JRootPane rootPane = getRootPane();
			
				//F1
				rootPane.getInputMap(cond).put(f1, "F1");
				rootPane.getActionMap().put("F1", pressF1);

Alguem sabe o que pode estar acontecendo?!

Desde já agradeço!

5 Respostas

Schoker

Ou…tem outro jeito de criar tecla de atalho?

E
  1. O jeito é esse mesmo
  2. Onde é a tal linha 1242 do arquivo PainelFinanceiro.java?
Schoker

a linha contem o codigo:

rootPane.getInputMap(cond).put(f1, "F1");
Schoker

consegui resolver o problema…

eu estava pondo este codigo em um JPanel…coloquei ele em um JDialog e funcionou…

:slight_smile:

E

Quem é null? o rootPane ou o inputMap(); Ponha um breakpoint nesse ponto do seu código, e veja qual dos dois está null.

Criado 8 de julho de 2010
Ultima resposta 8 de jul. de 2010
Respostas 5
Participantes 2