System.gui.confirm - Text Formatting

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