Search code examples
javafxnetbeans

how to automatically insert javafx code like netebeans8 in apache-netbeans 13++?


netbeans8 allow insert javafx bean properties with their setters and getters , but newer versions does not have that feature ( perhaps) . how can I do that in apache netbeans 13 ?


Solution

  • make code via macro

    enter image description here

    This example initializes a SimpleStringProperty with their imports (if they are available), and getter/setters.

    To implement it in Apache Netbeans, create a new macro using Tools > Options > Editor > Macros, name it, paste the code below as macro in the new macro you made, and finally create a shortcut.

    To use it, create an identifier and then, with the caret inside the identifier, press the macro's shortcut. That was Ctrl+Shift+Alt+1 in my case, but of course you might select a different shortcut.

    The macro can easily be modified for other property types, such as boolean, short, integer, etc...

    There are two versions shown below. The one to use depends on your "insert closing brackets automatically" setting, which is shown under Tools > Options > Editor > Code Completion:

    with "insert closing brackets automatically" turned off

    select-word caret-begin-word selection-end-word cut-to-clipboard  
    
    caret-line-first-column
    
     insert-tab "private final StringProperty " paste-from-clipboard " = new SimpleStringProperty();" insert-break
     insert-break   
    "public void " paste-from-clipboard make-setter "(String string) {" insert-break
      paste-from-clipboard ".set(string);" insert-break "}" insert-break
        
     insert-break   
      "public String " paste-from-clipboard make-getter "() {" insert-break
            "return " paste-from-clipboard ".get();" insert-break "}" insert-break
        
     insert-break   
      "public StringProperty " paste-from-clipboard  "() {" insert-break
        "    return " paste-from-clipboard " ;" insert-break
        "}" insert-break
    fix-imports  caret-up  caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up  caret-up caret-up
    

    with "insert closing brackets automatically" turned on

    select-word caret-begin-word selection-end-word cut-to-clipboard  
    
    caret-line-first-column
    
     insert-tab "private final StringProperty " paste-from-clipboard " = new SimpleStringProperty();" insert-break
     insert-break   
    "public void " paste-from-clipboard make-setter "(String string) {" insert-break
      paste-from-clipboard ".set(string);" insert-break "}" insert-break
        
     insert-break   
      "public String " paste-from-clipboard make-getter "() {" insert-break
            "return " paste-from-clipboard ".get();" insert-break "}" insert-break
        
     insert-break   
      "public StringProperty " paste-from-clipboard  "() {" insert-break
        "    return " paste-from-clipboard " ;" insert-break
      
    fix-imports  caret-up  caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up   caret-up caret-up