runelite-client/src/main/java/net/runelite/client/util/SwingUtil.java
/**
	 * Create swing button from navigation button.
	 *
	 * @param navigationButton the navigation button
	 * @param iconSize         the icon size (in case it is 0 default icon size will be used)
	 * @param specialCallback  the special callback
	 * @return the swing button
	 */
Create swing button from navigation button.
@param navigationButton the navigation button
@param iconSize         the icon size (in case it is 0 default icon size will be used)
@param specialCallback  the special callback
@return the swing button
Create swing button from navigation button . @param navigationButton the navigation button @param iconSize the icon size ( in case it is 0 default icon size will be used ) @param specialCallback the special callback @return the swing button
public static JButton createSwingButton(
		@Nonnull final NavigationButton navigationButton,
		int iconSize,
		@Nullable final BiConsumer<NavigationButton, JButton> specialCallback)
	{
		final BufferedImage scaledImage = iconSize > 0
			? resizeImage(navigationButton.getIcon(), iconSize, iconSize)
			: navigationButton.getIcon();
		final JButton button = new JButton();
		button.setName(navigationButton.getName());
		button.setToolTipText(navigationButton.getTooltip());
		button.setIcon(new ImageIcon(scaledImage));
		button.putClientProperty(SubstanceSynapse.FLAT_LOOK, Boolean.TRUE);
		button.setFocusable(false);
		button.addActionListener(e ->
		{
			if (specialCallback != null)
			{
				specialCallback.accept(navigationButton, button);
			}
			if (navigationButton.getOnClick() != null)
			{
				navigationButton.getOnClick().run();
			}
		});
		if (navigationButton.getPopup() != null)
		{
			final JPopupMenu popupMenu = new JPopupMenu();
			navigationButton.getPopup().forEach((name, callback) ->
			{
				final JMenuItem menuItem = new JMenuItem(name);
				menuItem.addActionListener((e) -> callback.run());
				popupMenu.add(menuItem);
			});
			button.setComponentPopupMenu(popupMenu);
		}
		navigationButton.setOnSelect(button::doClick);
		return button;
	}
public static JButton createSwingButton ( @ Nonnull final NavigationButton navigationButton , int iconSize , @ Nullable final BiConsumer < NavigationButton , JButton > specialCallback ) { final BufferedImage scaledImage = iconSize > 0 ? resizeImage ( navigationButton . getIcon ( ) , iconSize , iconSize ) : navigationButton . getIcon ( ) ; final JButton button = new JButton ( ) ; button . setName ( navigationButton . getName ( ) ) ; button . setToolTipText ( navigationButton . getTooltip ( ) ) ; button . setIcon ( new ImageIcon ( scaledImage ) ) ; button . putClientProperty ( SubstanceSynapse . FLAT_LOOK , Boolean . TRUE ) ; button . setFocusable ( false ) ; button . addActionListener ( e -> { if ( specialCallback != null ) { specialCallback . accept ( navigationButton , button ) ; } if ( navigationButton . getOnClick ( ) != null ) { navigationButton . getOnClick ( ) . run ( ) ; } } ) ; if ( navigationButton . getPopup ( ) != null ) { final JPopupMenu popupMenu = new JPopupMenu ( ) ; navigationButton . getPopup ( ) . forEach ( ( name , callback ) -> { final JMenuItem menuItem = new JMenuItem ( name ) ; menuItem . addActionListener ( ( e ) -> callback . run ( ) ) ; popupMenu . add ( menuItem ) ; } ) ; button . setComponentPopupMenu ( popupMenu ) ; } navigationButton . setOnSelect ( button :: doClick ) ; return button ; }
Create swing button from navigation button.
Create swing button from navigation button .