System.gui.confirm - Text Formatting

Hi, I am using the below script in button. But alignment of the text is not good. Any way to adjust my script?

i = 0
tag_check_neagtive = ["[default]Montreal/Weather/Description","[default]Montreal/Weather/Description","[default]Montreal/Weather/Description"]

negative_message = 'Minimum and Maximun retrieval modes for data extraction are unavailable for string type data. \nIf you want to proceed with other retrieval methods click OK. To remove these tags from the order click REMOVE.'
for y in tag_check_neagtive:
	
		negative_message = negative_message +'\n'+ str(tag_check_neagtive[i])
		
system.gui.confirm(negative_message,"Confirm")

can any help me for text formatting

You could try adding <html> to your string:

i = 0
tag_check_neagtive = ["[default]Montreal/Weather/Description","[default]Montreal/Weather/Description","[default]Montreal/Weather/Description"]

negative_message = '<html>Minimum and Maximun retrieval modes for data extraction are unavailable for string type data. \nIf you want to proceed with other retrieval methods click OK. To remove these tags from the order click REMOVE.'
for y in tag_check_neagtive:
	
		negative_message = negative_message +'\n'+ str(tag_check_neagtive[i])
		
system.gui.confirm(negative_message,"Confirm")

1 Like

One question
image

is there any way to rename yes and no button - instead of confirm and remove?

Not that I am aware of. Creating a custom pop-up window would probably be the simplest approach.

Custom popup any script you have with you?

Replace your current button code with something like this:
system.nav.openWindow('YourPopupPath/removeTagConfirm')

Then, create a custom popup window with the buttons you want. You will have to use a label in the popup for your message, The code will look something like this:

i = 0
tag_check_neagtive = ["[default]Montreal/Weather/Description","[default]Montreal/Weather/Description","[default]Montreal/Weather/Description"]

negative_message = 'Minimum and Maximun retrieval modes for data extraction are unavailable for string type data. \nIf you want to proceed with other retrieval methods click OK. To remove these tags from the order click REMOVE.'
for y in tag_check_neagtive:
	
		negative_message = negative_message +'\n'+ str(tag_check_neagtive[i])
		
event.source.parent.getComponent('tagDeleteConfirmationLabel').text = negative_message

Then you can program the confirm and remove buttons to do whatever you need them to do, and you can change the text properties of the buttons to whatever you want

1 Like

I assume that you will probably want to run the above script from the window’s internalFrameOpened event handler

1 Like

Another option would be to create your own JOptionPane instances. This requires some more scripting know-how, but is more powerful:
https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JOptionPane.html

2 Likes

Paul Griffith’s suggestion was actually pretty simple to implement. Now that I’ve used it, I remembered this post, and I’ve reformatted the code to fit the context of this question. Here it is:

from javax.swing import JOptionPane
i = 0
tag_check_neagtive = ["[default]Montreal/Weather/Description","[default]Montreal/Weather/Description","[default]Montreal/Weather/Description"]
negative_message = '<html>Minimum and Maximun retrieval modes for data extraction are unavailable for string type data. \nIf you want to proceed with other retrieval methods click OK. To remove these tags from the order click REMOVE.'
for y in tag_check_neagtive:
		negative_message = negative_message +'\n'+ str(tag_check_neagtive[i])
JOptionPane.showOptionDialog(None, negative_message, "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, ["Confirm", "Remove"], "Confirm")

The preceding code produces this result:

4 Likes

Hi,
image

can you please help in doing this type of Alert message box? as shown in fig.

Thank you

1 Like

Keeping it simple would look like this:

from javax.swing import JOptionPane
title = 'Your alert title'
message = 'Alert message here'
JOptionPane.showOptionDialog(None, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, None, ["Close"], title)

Result:
image

Thank you so much.
need to learn JAVA for Ignition scripting?

1 Like

Here is a more complex example, that shouldn't be too difficult for you to further develop into exactly what you are looking for. There really are no limitations when you are building these things from scratch:

from javax.swing import JOptionPane, JPanel, JLabel, JButton
from java.awt import Dimension, BorderLayout, FlowLayout, Color, Font
text = JLabel("Your alert title", JLabel.CENTER)
text.setForeground(Color.black)
text.setFont(Font("Serif", Font.BOLD, 34))
secondtext = JLabel("Alert message here", JLabel.CENTER)
secondtext.setForeground(Color.black)
secondtext.setFont(Font("Serif", Font.BOLD, 24))
button = JButton("Close")
button.background = Color.blue
button.foreground = Color.white
panel = JPanel()
panel.setPreferredSize(Dimension(400,110))
panel.setLayout(BorderLayout())
panel.add(text,BorderLayout.NORTH)
panel.add(button,BorderLayout.EAST)
buttonPanel = JPanel()
buttonPanel.setLayout(FlowLayout())
buttonPanel.add(secondtext)
buttonPanel.add(button)
button.setSize(100, 50)
panel.add(buttonPanel, BorderLayout.CENTER)
panel.setBackground(Color.white)
pane = JOptionPane
pane.showOptionDialog(None, panel, '', JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, None, [], "")				

Result:
image

2 Likes

At a minimum add the java docs to your bookmark bar. Ignition's class directory is quite useful as well.

Cool. And how to close now this dialog, when the blue 'Close' button is pressed...?

You'll have to add an action listener.

Here is the above example with an action listener added that closes the dialog:

Source Code:
from javax.swing import JOptionPane, JPanel, JLabel, JButton
from java.awt import Dimension, BorderLayout, FlowLayout, Color, Font
from javax.swing import SwingUtilities
def actionPerformed(event):
	parent = event.source
	parent = SwingUtilities.getRoot(parent)
	getWindows = parent.getWindows()
	for disposableWindow in getWindows:
		try:
			if disposableWindow.title == '':
				disposableWindow.setVisible(False)
		except:
			pass
text = JLabel("Your alert title", JLabel.CENTER)
text.setForeground(Color.black)
text.setFont(Font("Serif", Font.BOLD, 34))
secondtext = JLabel("Alert message here", JLabel.CENTER)
secondtext.setForeground(Color.black)
secondtext.setFont(Font("Serif", Font.BOLD, 24))
button = JButton("Close", actionPerformed=actionPerformed)
button.background = Color.blue
button.foreground = Color.white
panel = JPanel()
panel.setPreferredSize(Dimension(400,110))
panel.setLayout(BorderLayout())
panel.add(text,BorderLayout.NORTH)
panel.add(button,BorderLayout.EAST)
buttonPanel = JPanel()
buttonPanel.setLayout(FlowLayout())
buttonPanel.add(secondtext)
buttonPanel.add(button)
button.setSize(100, 50)
panel.add(buttonPanel, BorderLayout.CENTER)
panel.setBackground(Color.white)
pane = JOptionPane
pane.showOptionDialog(None, panel, '', JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, None, [], "")

Here is another example I've done in the past where the custom dialog automatically closes:

1 Like

Why this? It's not used anywhere...?

1 Like

Thanks. You are correct; it's not needed in this example. I'll delete it from the source code above.

1 Like