Annotation Type Action


  • @Retention(RUNTIME)
    @Target(FIELD)
    public @interface Action

    A component binding that will call a method when an action occurs. This can be applied to any object that has an "addActionListener" method that takes an ActionListener. Normally used for any sort of JButton or for a JTextField.

    Here's an example of using @Action annotations:
     public class BoundJCheckBoxExample {
    
         public static class Model extends DefaultBindableModel {
             private boolean state;
    
             public void setState(boolean state) {
                 this.state = state;
                 update();
             }
    
             public boolean isState() {
                 return state;
             }
          }
    
         public static class Controller {
             private final Model model;
    
             public Controller(Model model) {
                 this.model = model;
             }
    
             public void setToTrue() {
                 model.setState(true);
             }
    
             public void setToFalse() {
                 model.setState(false);
             }
         }
    
         private final Model model = new Model();
         @Bindable
         private final Controller controller = new Controller(model);
    
         @Bound(to = "state")
         private final JCheckBox box = new JCheckBox("State");
         @Bound(to = "state")
         private final JLabel stateLabel = new JLabel("?");
    
         @Action(call = "setToTrue")
         private final JButton trueButton = new JButton("Set True");
         @Action(call = "setToFalse")
         private final JButton falseButton = new JButton("Set False");
    
         private final JPanel panel = new JPanel();
    
         private final Bindings bindings = Bindings.standard();
    
         public BoundJCheckBoxExample() {
                // ... layout panel ...
                bindings.bind(this);
         }
    
         // main()
     }
     

    Methods available to @Actions

    The following are callable from @Actions:

    Disambiguation

    Strings passed into call() are disambiguated as follows:

    1. If the string uniquely identifies a model property or bindable method then there is no problem.
    2. If there are two or more possibilities then you must specify the field name in the string like "model1.state" or "fileController.close".
    3. You can always use the long form in (2) even if the short form would suffice.
    See Also:
    Bound
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String call
      The name of the method to call when the action occurs.
    • Element Detail

      • call

        java.lang.String call
        The name of the method to call when the action occurs. Must be accessible in the BindingContext.