Hi,
There is any way to change the size of a PopupMenu. Actually i’m using menu = system.gui.createPopupMenu to generate a Popup, the problem is that the Popup is to small (it doesn’t have à scrollbar). I need to show more the 50 items.
Have you any idea how put un scrollbar or change the size of a popup?
You can reach into advanced Swing coding and create your own popup menu - I’d suggest using JidePopupMenu as your base class, because it has some builtin niceties, such as scrolling if your menu items won’t fit on the screen. There’s probably some examples floating around this forum to get you started on the custom menu aspect.
Hi PGriffith,
I have tried to use the object but I do not have the necessary Java skills to do it. Can you guide me to some website or give me an idea to get started? How can I implement your suggestion in Ignition. I would really appreciate your help.
Thanks a lot
Low level Jython tutorials are few and far between. This is one resource that, on skimming, is at least accurate, although it looks like the formatting's been destroyed from whatever the original source was:
Honestly, lots of google results end up on this forum. Like I mentioned, there's some resources to be had:
Traceback (most recent call last):
File "<event:mousePressed>", line 117, in <module>
at com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities.createPopupMenu(WindowUtilities.java:728)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.NullPointerException: java.lang.NullPointerException
at org.python.core.Py.JavaError(Py.java:552)
at org.python.core.Py.JavaError(Py.java:543)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:523)
at org.python.core.PyObject.__call__(PyObject.java:497)
at org.python.core.PyObject.__call__(PyObject.java:501)
at org.python.pycode._pyx24.f$0(<event:mousePressed>:118)
at org.python.pycode._pyx24.call_function(<event:mousePressed>)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:781)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:297)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
at com.sun.proxy.$Proxy59.mousePressed(Unknown Source)
at java.desktop/java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.desktop/java.awt.Component.processEvent(Unknown Source)
at java.desktop/java.awt.Container.processEvent(Unknown Source)
at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities.createPopupMenu(WindowUtilities.java:728)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
... 44 more
Ignition v8.1.0 (b2020110211)
Java: Azul Systems, Inc. 11.0.7
Hi PGriffith:
It has been some time since the last time. In fact, I have had to attack other points of the application in which I am working. Now I have a little more time and I have taken up the problem of this topic. However, I am still stuck, here is what I have done:
The scrollbar still does not appear. If I not wrong, the JpopupMenu have acces of all attributs of Jcomponent, so the scrollable attribute. So, I don’t understand why it doesn’t appear.
JPopupMenus don’t automatically scroll, and you’re making a JyPopupMenu anyways. You must use JidePopupMenu as your base class if you want the automatic scrolling behavior. The code to add new items should be basically the same.
It’s not my component, but yes, it’s supposed to do what you want:
public class JidePopupMenu
extends JPopupMenu
implements Scrollable
This component extends JPopupMenu and adds a method to display the menu inside the screen even if the mouse pointer is near the edge of the screen.
It also puts the menu items into a scroll pane. When there are too many menu items that can't fit into one screen, the scroll pane will scroll up and down so that you can still get to all menu items.
I don’t know why it’s not doing what it’s supposed to.
Can this script be adapted to maintain the nested list functionality of system.gui.createPopupMenu? It gets hung up when passing the submenu names and functions.
Instead of creating JMenuItems, create your own JMenus (sibling import to JMenuItem) and add your nested menus to them.
Constructing that automatically I’ll leave as an exercise for the reader. We could probably change system.gui.createPopupMenu to use this different base class automatically, but it won’t happen anytime soon, so you’re probably still better off using a workaround.