john renfrew Posted May 17, 2010 Posted May 17, 2010 (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 May 17, 2010 by Guest
john renfrew Posted May 17, 2010 Author Posted May 17, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now