Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 /*
  * Copyright (C) 2006 Sun Microsystems, Inc. All rights reserved. Use is
  * subject to license terms.
  */ 
 
 package examples;
 
The enabledProperty @Action annotation parameter.

This example is nearly identical to ActionExample1. We've added a parameter to the @Action annotation for the clearTitle action:

 @Action(enabledProperty = "clearEnabled")
 public void clearTitle() { 
     appFrame.setTitle(textField.getText());
     setClearEnabled(true);
 }
 
The annotation parameter names a bound property from the same class. When the clearEnabled property is set to false, as it is after the window's title has been cleared, the clearTitle Action is disabled.

Author(s):
Hans Muller (Hans.Muller@Sun.COM)
public class ActionExample3 extends Application {
    private JFrame appFrame = null;
    private JTextField textField = null;
    private boolean clearEnabled = false;
    @Action public void setTitle() {
    }
    @Action(enabledProperty = "clearEnabled")
    public void clearTitle() {
    }
    public boolean isClearEnabled() {
	return ;
    }
    public void setClearEnabled(boolean clearEnabled) {
	boolean oldValue = this.;
	this. = clearEnabled;
	firePropertyChange("clearEnabled"oldValuethis.);
    }
    @Override protected void startup() {
	 = new JFrame("");
	 = new JTextField("<Enter the window title here>");
        .setFont(new Font("LucidSans"., 32));
	JButton clearTitleButton = new JButton("Set Window Title");
	JButton setTitleButton = new JButton("Clear Window Title");
	JPanel buttonPanel = new JPanel();
	buttonPanel.add(setTitleButton);
	buttonPanel.add(clearTitleButton);
	.add(buttonPanel.);
	/* Lookup up the Actions for this class/object in the
	 * ApplicationContext, and bind them to the GUI controls.
	 */
	ActionMap actionMap = getContext().getActionMap();
	setTitleButton.setAction(actionMap.get("setTitle"));
	.setAction(actionMap.get("setTitle"));
	clearTitleButton.setAction(actionMap.get("clearTitle"));
    }
    public static void main(String[] args) {
        Application.launch(ActionExample3.classargs);
    }
New to GrepCode? Check out our FAQ X