### Create Dialogs using Java Swing

To create dialogs, the Java Swing Library offers various methods (requires the JavaObject library).
Read more here:
http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
Some examples below.
There many more variations of usage. Read the documentation, but the principle usage remains the same as shown.
Hints
For the optionType use an Int starting at 0 (see the documentation):
DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, or OK_CANCEL_OPTION
For the messageType use an Int starting at 0 (see the documentation):
ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
HTML formatted strings can be displayed by putting
in front of the string:
"
Two
lines
"
showMessageDialog
' Returns null
jo.RunMethod("showMessageDialog", Array As Object(Null, "Hello World"))
' With HTML formatted string
jo.RunMethod("showMessageDialog", Array As Object(Null, "
Two
lines
", "Title", 2))
showConfirmDialog
' Returns 0 = Yes, 1 = No, 3 = Cancel
Dim nRT As Int = jo.RunMethod("showConfirmDialog", Array As Object(Null, "Please Confirm."))
Log("showConfirmDialog: " & nRT)
showOptionDialog
' Returns 0 = A etc.
Dim nRT As Int = jo.RunMethod("showOptionDialog", Array As Object(Null, "Select an Option", "Title", 1, 1, Null, Array As Object("A", "B", "C"), Null))
Log("showOptionDialog: " & nRT)
showInputDialog
' Returns Input as text
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object("Your input please:"))
Log("showInputDialog: " & strInput)
' Returns Input as text
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object("Your input please:", "Hello World"))
Log("showInputDialog: " & strInput)
' Returns Input as text
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object(Null, "Your input please:", "Title", 2))
Log("showInputDialog: " & strInput)
' Returns Input as text
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object(Null, "Your input please:", "Title", 1, 1, Null, Array As Object("A", "B", "C"), Null))
Log("showInputDialog: " & strInput)
Complete set of Swing Dialogs to be included
' Show Messagedialog
' Parameter Message as String
`Public Sub showMessage(strMsg As String)
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
' Show the message
jo.RunMethod("showMessageDialog", Array As Object(Null, strMsg))
End Sub`
' Show Messagedialog
' Parameter Message as String
' Parameter Heading as String
' Parameter Messagetype as Int
`Public Sub showMessage2(strMsg As String, strHdg As String, nMsgType As Int)
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
' Show the message
jo.RunMethod("showMessageDialog", Array As Object(Null, strMsg, strHdg, nMsgType))
End Sub`
' Show confirmation dialog
' Parameter Message as String
' Returns 0 = Yes, 1 = No, 2 = Cancel
`Public Sub showConfirmDialog(strMsg As String)
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
Dim nRT As Int = jo.RunMethod("showConfirmDialog", Array As Object(Null, strMsg))
Log("showConfirmDialog: " & nRT)
End Sub`
' Returns Option selected as a string
`Public Sub showOptionDialog(strMsg As String, strTitle As String, optionType As Int, msgType As Int, lstOptions As List)
' Convert the list into an array of objects
Dim objOptions(lstOptions.Size) As Object
For i = 0 To lstOptions.Size - 1
objOptions(i) = lstOptions.Get(i)
Next
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
Dim nRT As Int = jo.RunMethod("showOptionDialog", Array As Object(Null, strMsg, strTitle, optionType, msgType, Null, objOptions, Null))
Log("showOptionDialog: " & nRT)
End Sub`
`Public Sub showInputDialog(strMsg As String)
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
' Returns Input as text
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object(strMsg))
Log("showInputDialog: " & strInput)
End Sub`
' Returns Input as text
`Public Sub showInputDialog2(strMsg As String, strTitle As String)
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object(strMsg, strTitle))
Log("showInputDialog: " & strInput)
End Sub`
' Returns Input as text
`Public Sub showInputDialog3(strMsg As String, strTitle As String, nType As Int)
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object(Null, strMsg, strTitle, nType))
Log("showInputDialog: " & strInput)
End Sub`
' Returns Input as text
`Public Sub showInputDialog4(strMsg As String, strTitle As String, nType As Int, lstOptions As List)
' Convert the list into an array of objects
Dim objOptions(lstOptions.Size) As Object
For i = 0 To lstOptions.Size - 1
objOptions(i) = lstOptions.Get(i)
Next
' Define the JavaObject
Dim jo As JavaObject
' Initialize using the Swing Library class JOptionPane
jo.InitializeStatic("javax.swing.JOptionPane")
Dim strInput As String = jo.RunMethod("showInputDialog", Array As Object(Null, strMsg, strTitle, nType, Null, objOptions, Null))
Log("showInputDialog: " & strInput)
End Sub`
' Show About Message
' Parameter Message as String
Publc Sub showAbout(strMsg As String)
showMessage2(strMsg, "About", ICON_INFORMATION)
End Sub

Changed: , Category: JavaObject, File: T6C208M1522.htm, ID: 1522