# Using Java and Jython in ignition

**URL:** <https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037>\
**Category:** Ignition\
**Created:** [February 21, 2012, 4:57pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037 "2012-02-21T16:57:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 21, 2012, 4:57pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/1 "2012-02-21T16:57:39Z")

</div>

Please someone show me how to get this to work inside an ignition window.

[jython.org/jythonbook/en/1.0 … tions.html](http://www.jython.org/jythonbook/en/1.0/GUIApplications.html)

```auto
from javax.swing import JButton, JFrame

frame = JFrame('Hello, Jython!',
            defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
            size = (300, 300)
        )

def change_text(event):
    print 'Clicked!'

button = JButton('Click Me!', actionPerformed=change_text)
frame.add(button)
frame.visible = True
```

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [February 21, 2012, 6:06pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/2 "2012-02-21T18:06:27Z")

</div>

Put that in the OnPaint event of a PaintableCanvas component in the designer.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 21, 2012, 7:28pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/3 "2012-02-21T19:28:47Z")

</div>

My only option is the repaint event. I get the following error.

Traceback (innermost last):  
File “event:repaint”, line 14, in ?  
NameError: True

```
at org.python.core.Py.NameError(Py.java)
at org.python.core.PyFrame.getglobal(PyFrame.java)
at org.python.core.PyFrame.getname(PyFrame.java)
at org.python.pycode._pyx68.f$0(<event:repaint>:14)
at org.python.pycode._pyx68.call_function(<event:repaint>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:395)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:139)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:247)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at $Proxy7.repaint(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.PMIPaintableCanvas.paintComponent(PMIPaintableCanvas.java:122)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at com.inductiveautomation.vision.api.client.components.model.AbstractVisionPanel.paintChildren(AbstractVisionPanel.java:222)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(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)

```

Ignition v7.3.3 (b570)  
Java: Sun Microsystems Inc. 1.6.0\_29

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/1X/20274a8b05e3b116ad7baf3e05a61a357f052ae9.jpg)

---

<div class="post-metadata">

**Author:** ![Greg.Buehler](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@Greg.Buehler](https://forum.inductiveautomation.com/u/Greg.Buehler)\
**Post date:** [February 21, 2012, 8:32pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/4 "2012-02-21T20:32:15Z")

</div>

Jython doesn’t define “True” or “False” as constant variables. Changing `frame.visible = True` to `frame.visible = 1` makes it work.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 21, 2012, 9:42pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/5 "2012-02-21T21:42:21Z")

</div>

That worked with 1 instead of True. The script above came from they jython site and they used True in their example. Maybe a JFrame isn’t what I am looking for. I need it to fill the paintable canvas or empty container, not pop out like this JFrame example does.

I am getting frustrated with this. I wish I would have stuck with php or .net. Or even a LogiXML type app. My PLC guy talked me into using this because we could display his PLC info and create a complete data driven application with a GUI that was easily to customize. Other than the cookie cutter stuff here, this is not so easy to customize.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 21, 2012, 9:47pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/6 "2012-02-21T21:47:58Z")

</div>

[quote=“ecujak”]That worked with 1 instead of True. The script above came from they jython site and they used True in their example. Maybe a JFrame isn’t what I am looking for. I need it to fill the paintable canvas or empty container, not pop out like this JFrame example does.

I am getting frustrated with this. I wish I would have stuck with php or .net. Or even a LogiXML type app. My PLC guy talked me into using this because we could display his PLC info and create a complete data driven application with a GUI that was easily to customize. Other than the cookie cutter stuff here, this is not so easy to customize.[/quote]

What kind of UIs are you looking to create?

---

<div class="post-metadata">

**Author:** ![rhoag](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rhoag](https://forum.inductiveautomation.com/u/rhoag)\
**Post date:** [February 22, 2012, 4:51am UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/7 "2012-02-22T04:51:08Z")

</div>

I believe ecujak wants to insert a JButton inside the paintable canvas (not create a new JFame popup). Is it possible do this? Also is it possible to insert a JRadioButton or JCheckBox inside a paintable canvas?

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 22, 2012, 2:35pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/8 "2012-02-22T14:35:20Z")

</div>

> [@rhoag](#):
>
> to insert a JButton inside the paintable canvas (not create a new JFame popup). Is it possible do this? Also is it possible to insert a JRadioButton or JCheckBox inside a paintable canvas?

Yes. I am glad someone is seeing what I am looking for. I am not the best communicator, I am sorry.

I want to be able to get a dataset based on whatever query my filters generate. I want to display each record of that dataset in a way that will be user friendly with whatever logic or presentation I want to use. The rigid table view option available out of the box from ignition isn't going to work for me.

For each record I want to display Buttons(edit, delete, toggle, check box radio, dropdown), text, text boxes, and other items with nice looking formatting and flow based on record by record and item by item logic.

Ignition may be able to do all of this, but if it is... it is not documented very well. There are not very many examples and the examples that are there are only a hint of what is needed.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 22, 2012, 2:43pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/9 "2012-02-22T14:43:42Z")

</div>

I don’t need java or jython. If I could just script the building of the components available in ignition, that would be enough.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 24, 2012, 9:55pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/11 "2012-02-24T21:55:23Z")

</div>

The problem is right now you cannot dynamically add Ignition components to the runtime. If you don’t use the table you have to add enough components for the max case and make them visible when needed.

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [February 24, 2012, 10:43pm UTC](https://forum.inductiveautomation.com/t/using-java-and-jython-in-ignition/4037/12 "2012-02-24T22:43:29Z")

</div>

> [@](#):
>
> Take that Duke and run....

Really?

Anyhow, I think you're a bit off track in how you're approaching the problem. When you start talking about the paintable canvas, you're quickly getting into territory where you're going to have to fend for yourself. Frankly, I don't know why the paintable canvas is included as part of the standard components- it really requires quite a bit of expertise to use.

Traditionally, what you want to do is accomplish by using break-out edit forms. In other words, you have some sort of selection mechanism (a table, a list, etc.), and then you have components on the window, which reference the current selection. If you have different types of edit scenarios, you can break out the editing to a different window, and open the correct one for the selected type, or create different panels on a screen, and only make the applicable panel visible.

Ultimately, Ignition offers very little support for dynamically generating displays. Better support for this is occasionally requested, but perhaps not as often as you might imagine.

Let me know if this makes sense, or if you don't think it would work for some reason.

Regards,
