# Customized Message Box - Vision

**URL:** <https://forum.inductiveautomation.com/t/customized-message-box-vision/64578>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [September 28, 2022, 7:43am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578 "2022-09-28T07:43:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 28, 2022, 7:43am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/1 "2022-09-28T07:43:27Z")

</div>

Hi  
I would like to have a message box with no ok button.  
And also i would like to customize it to look like a toastr.  
Is there any options available in ignition?

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [September 28, 2022, 8:10am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/2 "2022-09-28T08:10:34Z")

</div>

> [@Toast Notifications](https://forum.inductiveautomation.com/t/toast-notifications/15522/6):
>
> Here is my way of doing this. I wrote this when 7.0 came out, so I would expect there are quite a few upgrades. The benefit of this method is the toast notification will pop up outside of the Ignition window, so if the user is browsing the web, watching porn, etc, this will pop up on top of that. Call the method with path.to.createNotifier() notifiers = [] def createNotifier(title="Hello", bodyText="World", time = 5000, bgColor=None, textColor=None): from javax.swing import JFrame,JLabel,JT…

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2022, 8:11am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/3 "2022-09-28T08:11:29Z")

</div>

Yes. You can make a custom JOptionPane  
Example:

```auto
from javax.swing import JOptionPane
JOptionPane.showOptionDialog(None, "What Choices do we have?", "Not Okay!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, ["Not Okay!", "Really Not Okay!"], "Confirm")

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/d/bd2e220904e34f0c84e3a334d071817c0c684556.png)

Edit:  
[Additional information Here:](https://forum.inductiveautomation.com/t/system-gui-confirm-text-formatting/63750/8)

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 28, 2022, 8:40am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/4 "2022-09-28T08:40:13Z")

</div>

Is there any way to have a messagbox with no option to be selected?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2022, 8:51am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/5 "2022-09-28T08:51:58Z")

</div>

Yes. Just leave the choice list blank

```auto
from javax.swing import JOptionPane
JOptionPane.showOptionDialog(None, "There are no options!!!", "What are the options???", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, [], "Confirm")

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f5c501a277681ad390e185b6500122e468b15a5b.png)

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 28, 2022, 8:56am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/6 "2022-09-28T08:56:19Z")

</div>

> [@justinedwards.jle](#):
>
> `JOptionPane.QUESTION_MESSAGE`

Is it possible not to have the close option and close the message box within few secs

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 28, 2022, 8:56am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/7 "2022-09-28T08:56:41Z")

</div>

Is it possible not to have the close option and close the message box within few secs

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2022, 8:59am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/8 "2022-09-28T08:59:50Z")

</div>

I imagine so, but I’ve never attempted it.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 28, 2022, 10:21am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/9 "2022-09-28T10:21:42Z")

</div>

By the time you get to no buttons and no close option, you have yourself a popup. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2022, 11:26am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/10 "2022-09-28T11:26:30Z")

</div>

@JordanCClark

What you’re saying makes perfect sense, but can you blame me? Who could resist the opportunity to make goofy custom message boxes?

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [September 28, 2022, 12:07pm UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/11 "2022-09-28T12:07:58Z")

</div>

> [@Auto - Close Error Box](https://forum.inductiveautomation.com/t/auto-close-error-box/12786/17):
>
> Some time ago I had need for a suite of Java dialog boxes that would close after a time out, since the kiosk type client sessions were subject to being abandoned, and I didn’t want leftover dialog boxes hanging around for the next user. Admittedly, the most rock-solid way to do this is just make pop-up windows that contain timers to close themselves. However, I’ve used the attached Java dialog boxes with good success for quite a while now. As-is, these require a boolean client tag “Dialog\_Box\_O…

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2022, 1:09pm UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/12 "2022-09-28T13:09:42Z")

</div>

Okay, I attempted it using some of the guidance from @zxcslo.

This solution is tested and works:

```auto
def disposeDialog():
    def closeWindow():
		from javax.swing import SwingUtilities
		parent = event.source
		parent = SwingUtilities.getRoot(parent)
		getWindows = parent.getWindows()
		for disposableWindow in getWindows:
			try:
				if disposableWindow.title == "Options":
					disposableWindow.setVisible(False)
			except:
				pass
    system.util.invokeLater(closeWindow,3000)
    from javax.swing import JOptionPane
    JOptionPane.showOptionDialog(None, "Problem message", "Options", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, [], "")        
system.util.invokeAsynchronous(disposeDialog)

```

It opens a custom dialog box and closes it automatically after three seconds.

The key information is the title. So in the if statement: `if disposableWindow.title == "Options":`

The title `"Options"` comes from the third argument of the `JOptionPane.showOptionDialog()` command.

Edit: Updated deprecated `.hide()` method to `.setVisible(False)`

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 29, 2022, 4:47am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/13 "2022-09-29T04:47:06Z")

</div>

Hi,  
Thanks for the suggestion.  
I am using the button as a template.  
So I have included the given script in custom method.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/b/5b3ca9ef3cfa462b80f97fbba20b04af29a42eb7.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/e/4e4e9b01360fb697826ea99ff1325d46d8ea3855.png)  
Is it right to use like this?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 29, 2022, 5:01am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/14 "2022-09-29T05:01:41Z")

</div>

Yes. It will work as expected. However, a couple of things will need to be changed.  
**1.** In your **actionPerformed** script, change `self.disposeDialog()` to `event.source.disposeDialog()`  
**2.** in your **disposeDialog** custom method, the upper definition will still be required, and everything will have a minimum of one tab spacing. Also` parent = event.source` will need to be changed to `parent = self`  
All together, the custom method script will look like this:

```auto
def disposeDialog(self):
	"""
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
	"""
	def disposeDialog():
	    def closeWindow():
			from javax.swing import SwingUtilities
			parent = self
			parent = SwingUtilities.getRoot(parent)
			getWindows = parent.getWindows()
			for disposableWindow in getWindows:
				try:
					if disposableWindow.title == "Options":
						disposableWindow.setVisible(False)
				except:
					pass
	    system.util.invokeLater(closeWindow,3000)
	    from javax.swing import JOptionPane
	    JOptionPane.showOptionDialog(None, "Problem message", "Options", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, [], "")        
	system.util.invokeAsynchronous(disposeDialog)

```

Edit: Updated deprecated `.hide()` method to `.setVisible(False)`

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 29, 2022, 5:21am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/15 "2022-09-29T05:21:59Z")

</div>

Another thing of note, I used the `.hide()` method from the JComponent class to close the window, but this has been [deprecated](https://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#hide()). I should have used the more current `.setVisible(False)`, so if you’ve already implemented the code I originally posted, you will probably want to change this accordingly.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 29, 2022, 5:39am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/16 "2022-09-29T05:39:23Z")

</div>

Hey Justin,

Thank you so much… It works!!!.  
Is it possible to change background color, size??

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 29, 2022, 7:35am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/17 "2022-09-29T07:35:49Z")

</div>

Yes, but you will have to add a JPanel to the dialog box. Here is an example using your custom method:

```auto
def disposeDialog(self):
	"""
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
	"""
	def disposeDialog():
		def closeWindow():
			from javax.swing import SwingUtilities
			parent = self
			parent = SwingUtilities.getRoot(parent)
			getWindows = parent.getWindows()
			for disposableWindow in getWindows:
				try:
					if disposableWindow.title == "Options":
						disposableWindow.setVisible(False)
				except:
					pass
		system.util.invokeLater(closeWindow,3000)
		from javax.swing import JOptionPane
		from javax.swing import JPanel
		from javax.swing import JLabel
		from java.awt import Dimension
		from java.awt import BorderLayout
		from java.awt import Color
		from java.awt import Font
		text = JLabel("Problem message", JLabel.CENTER)
		text.setForeground(Color.white)
		text.setFont(Font("Serif", Font.BOLD, 48))
		panel = JPanel()
		panel.setPreferredSize(Dimension(500,500))
		panel.setLayout(BorderLayout())
		panel.add(text,BorderLayout.CENTER)
		panel.setBackground(Color.black)
		pane = JOptionPane
		pane.showOptionDialog(None, panel, "Options", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, None, [], "")				
	system.util.invokeAsynchronous(disposeDialog)

```

**The proceeding code produces the following result:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/7513e34b6ff2dfb44fae9d570e6fc3245fdd85e9.png)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 29, 2022, 7:38am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/18 "2022-09-29T07:38:08Z")

</div>

It shouldn’t be too difficult to tweak the parameters in that code to meet your usage needs.

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 29, 2022, 9:20am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/19 "2022-09-29T09:20:22Z")

</div>

> [@justinedwards.jle](#):
>
> `YES_NO_OPTION`

Thank you so much Justin

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [September 30, 2022, 5:52am UTC](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578/20 "2022-09-30T05:52:20Z")

</div>

Hey Justin,

Is this possible to have this code in the project library, so that i can use it over the prject whenever i wanna display a popup for eg say."Loading".  
When I try to implement as i said before, i am getting error in 'parent'

[Next page](https://forum.inductiveautomation.com/t/customized-message-box-vision/64578.md?page=2)
