# It´s possible add a button on IDE?

**URL:** <https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359>\
**Category:** Project Guidance\
**Created:** [December 29, 2022, 11:00am UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359 "2022-12-29T11:00:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 29, 2022, 11:00am UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359/1 "2022-12-29T11:00:18Z")

</div>

Hello community!  
I have a question, would it be possible to add an extra button in the IDE next to the play and stop button to launch a custom script?

Exists any version of custom IDE?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [December 29, 2022, 2:11pm UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359/2 "2022-12-29T14:11:36Z")

</div>

Hi @erkosone,

Can’t show you a concrete example by now as I’ve currently only mobile access, but take a look here …

> **[Tool Basics · processing/processing Wiki](https://github.com/processing/processing/wiki/Tool-Basics)**
>
> Source code for the Processing Core and Development Environment (PDE) - Tool Basics · processing/processing Wiki

If I find a bit time the next days I’ll try to provide a working example …

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [December 30, 2022, 8:34am UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359/3 "2022-12-30T08:34:08Z")

</div>

Thanks for the info 😉

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 3, 2023, 10:52am UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359/4 "2023-01-03T10:52:48Z")

</div>

Hi @erkosone,

As promised, here is an working example of how one could add a button to the PDE.  
However, I must say that this is not intended in principle and is therefore more or less a small hack.  
_I would recommend to just add a sub-item in the Tools menu that would then execute what you want, described in the docs from above._

The example is based on the Java Mode Toolbar and I just reused the styles from the Run button, but one could just use ie. a JButton as well. The Tool extension works on both P3 and P4.

> **Code Example**
>
> ```auto
> import java.awt.Component;
> import java.awt.Container;
> import java.awt.EventQueue;
> import java.awt.event.ActionEvent;
> import java.util.ArrayList;
> 
> import javax.swing.Box;
> import javax.swing.JOptionPane;
> 
> import processing.app.Base;
> import processing.app.tools.Tool;
> import processing.app.ui.Editor;
> import processing.app.ui.EditorButton;
> import processing.app.ui.EditorToolbar;
> import processing.app.ui.Toolkit;
> 
> public class DummyButtonExample implements Tool {
> private Base base;
> private Editor editor;
> 
> public String getMenuTitle() {
> return "##tool.name##";
> }
> 
> private ArrayList<Component> getAllComponents(final Container parentContainer) {
> Component[] components = parentContainer.getComponents();
> ArrayList<Component> componentList = new ArrayList<Component>();
> for (Component c : components) {
> componentList.add(c);
> if (c instanceof Container)
> componentList.addAll(getAllComponents((Container) c));
> }
> return componentList;
> }
> 
> public void init(Base base) {
> this.base = base;
> this.editor = base.getActiveEditor();
> try {
> EventQueue.invokeLater(new Runnable() {
> public void run() {
> ArrayList<Component> allComponents = getAllComponents(editor.getRootPane());
> Component myParent = allComponents.get(13); // JavaEditor Toolbar
> Component myAddon = allComponents.get(14); // Underlying container for buttons
> @SuppressWarnings("serial")
> EditorButton myButton = new EditorButton((EditorToolbar) myParent, "/lib/toolbar/run", "MyButton") {
> @Override
> public void actionPerformed(ActionEvent e) {
> // do what should be happen on button pressed
> JOptionPane.showMessageDialog(null, "MyButton Pressed!", "Info", JOptionPane.INFORMATION_MESSAGE);
> }
> };
> ((javax.swing.Box) myAddon).add(myButton, 5);
> ((javax.swing.Box) myAddon).add(Box.createHorizontalStrut(Toolkit.zoom(9)), 6);
> }
> });
> } catch (Exception e) {
> System.err.println("Exception at invoke DummyButtonExample EventQueue: " + e.getMessage());
> }
> }
> 
> public void run() {
> // do nothing
> }
> }
> 
> ```

![Button](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/1/811a5880950ca80ec89780b1216288e7b2dba637.gif)

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![erkosone](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@erkosone](https://discourse.processing.org/u/erkosone)\
**Post date:** [January 3, 2023, 2:10pm UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359/5 "2023-01-03T14:10:51Z")

</div>

Muchas gracias por interesarte en el tema 😊. Has recompilado el ide?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 3, 2023, 2:45pm UTC](https://discourse.processing.org/t/it-s-possible-add-a-button-on-ide/40359/6 "2023-01-03T14:45:58Z")

</div>

Hi @erkosone,

> [@erkosone](#):
>
> Has recompilado el ide?

No! The Tool works as a kind of addon/plugin to the PDE.

Just study the information from here …

> **[Tool Basics](https://github.com/processing/processing/wiki/Tool-Basics)**
>
> Source code for the Processing Core and Development Environment (PDE) - processing/processing

And here…

> **[GitHub - processing/processing-tool-template: Processing Tool Template for...](https://github.com/processing/processing-tool-template)**
>
> Processing Tool Template for Eclipse. Contribute to processing/processing-tool-template development by creating an account on GitHub.

Cheers  
— mnse
