GenericDialog gd = new GenericDialog("Test");
// Create custom button
Button bt = new Button("Custom Button");
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
IJ.log("You clicked the button");
}
});
// Add and show button
gd.add(bt);
gd.showDialog();
You can modify the GenericDialog class or create your own class. If you are a bit rusty an Action Listeners, I recommend checking out these tutorials:
http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.htmlhttp://www.javaprogrammingforums.com/java-code-snippets-tutorials/278-how-add-actionlistener-jbutton-java-swing.html
Sarkoy wrote
I'm working with a photometer, and have created a dialog box that asks the user the specifications of the aperture (selection) he wants. After selecting "oval" or "rectangle," the user is prompted to enter the x and y coordiantes of the upper left corner, and the width and height.
It would be great if I could add an additional button that would allow for the selection the user has defined to be displayed on the image, without the user having to press "OK," so that the user could adjust the measurements if needed. I realize I could do this with new dialog boxes opening, one saying "correct aperter?" that would allow the user to redo the process, bu that would be a bit tedious.
Is there a way I can add in an additional button that when pressed would fire a line of code, without closing the dialog box?
Thanks.