Veröffentlicht 4. Juni 200421 j In Swing ist es ja so, dass man eine AbstractAction ableiten kann und dann in ein JMenu oder eine JToolBar einsetzen kann. Ich hab mir so eine Action gebaut. Nun ist es aber so, dass diese Action nur im JMenu einen Actioncommand bekommt, nicht aber in der Toolbar! Was mache ich falsch? Ich bin das Problem umgangen indem ich folgendes geschrieben habe: // ActionExample.java extends JPanel .... SampleAction exampleAction = new SampleAction("Download", new ImageIcon("images/download.gif")); menu.add(exampleAction); JButton down = toolbar.add(exampleAction); down.setActionCommand("Downloadbutton"); .... _______________________________________________________________ // SampleAction.java extends AbstractAction class SampleAction extends AbstractAction { public SampleAction(String text, ImageIcon img) { super(text,img); } /* (non-Javadoc) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { System.out.println("Action ["+e.getActionCommand()+"] performed..."); } } Mir kommt es aber darauf an, dass der ActionCommand in der SampleAction.class schon gesetzt wird!
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.