Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

AbstractAction in JToolbar bekommt keinen Actioncommand

Empfohlene Antworten

Veröffentlicht

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.