Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5322 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted (edited)

I am trying to accelerate my learning by looking at extending some of the examples as well as writing my own

After doing some swingbuilder learning today I wanted to make sure I could capture the returns from the dialog.

I have amended it so that it will take multiple button values in a list

as:

// DynamicMessage ( fm_Title, fm_Message, fm_Buttons

// creates a dialog with html body and buttons from a return sep list

//  captures exit values as false and ESC is -1 (int)



import groovy.swing.SwingBuilder



swing = new SwingBuilder()

buttons = fm_Buttons.split('n')

def dialog = swing.optionPane(

  message:fm_Message, options:(buttons)

)

dialog.createDialog(null, fm_Title).show()

if ( dialog.getValue() == null) {

	return false

}

return dialog.getValue()

BUT if you close the dialog with no choice it returns null, if you dismiss by ESCAPING it returns -1 as an integer and in all other cases it returns the string value of the button

if you try and do Integer.toString(dialog.getValue() to test if it is a literal "-1" then of course it fails when the response is a button string.

Anyone any ideas how to achieve this??

I am just trying to capture how a user leaves the dialog box in more detail...

Edited by Guest
Posted

Just updated so the button number rather than the value is returned

Only problem is still with the ESC key causing an error to be thrown at is is an not string

// DynamicMessage ( fm_Title, fm_Message, fm_Buttons

// creates a dialog with html body and buttons from a list, captures exit values as false and ESC is -1 (int)

// amended version which captures button pressed as numeric value so can be

// used like FM Get(LastMessage Choice)

/// still needs ESC value sorting - throws error



import groovy.swing.SwingBuilder



swing = new SwingBuilder()

buttons = fm_Buttons.split('n')

test = buttons.join(",")

zerobut = buttons.size() - 1

int bnum = 0

int i = 0

test = ""

def dialog = swing.optionPane(

  message:fm_Message, options:(buttons)

)

dialog.createDialog(null, fm_Title).show()

if ( dialog.getValue() == null) {

	return false

}

buttons.each(){

	i = i + 1

	if ( it == dialog.getValue()){

	bnum = i

	} else {

	bnum = bnum

	}

}

if (bnum > 0) {

	return bnum

}

return "ERROR"

// at the moment

This topic is 5322 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.