2017-12-27 2 views
0

Ich versuche, diesen Code für die Show ein Bild in dem Panel zu verwenden und dann das Bild aktualisieren, wenn klicken, aber nicht funktioniert (nicht das Bild Aktualisierung)Wie könnte ich groovy Bild im Panel aktualisieren, wenn Sie auf eine Schaltfläche klicken?

diesen Fehler:

Exception in thread "AWT-EventQueue-0" groovy.lang.MissingPropertyException: No such property: label

I don‘ Ich weiß nicht, wie ich updaten könnte.

dies ist mein Code:

@Bindable 
class Address { 
    String street, number, city 
    String toString() { "address[street=$street,number=$number,city=$city]" } 
} 



def address = new Address(street: 'Evergreen Terrace', number: '742', city: 'Springfield') 
    def BL = new BorderLayout() 

def swing = new SwingBuilder() 
def swingBuilder = new SwingBuilder() 
swingBuilder.edt { // edt method makes sure UI is build on Event Dispatch Thread. 


    lookAndFeel 'nimbus' // Simple change in look and feel. 

    frame(title: 'Address', size: [1000, 800], 
      show: true, locationRelativeTo: null, 

      defaultCloseOperation: EXIT_ON_CLOSE) { 

     borderLayout(vgap: 5) 

     panel(constraints: BorderLayout.CENTER, 
       border: compoundBorder([emptyBorder(10), titledBorder('Enter your address:')])) { 
      tableLayout { 

       tr { 
        td { 
         label 'Street:' // text property is default, so it is implicit. 
        } 
        td { 
         textField address.street, id: 'streetField', columns: 20 
        } 
       } 
       tr { 
        td { 
         label 'Number:' 
        } 
        td { 
         textField id: 'numberField', columns: 5, text: address.number 
        } 
       } 
       tr { 
        td { 
         label 'City:' 
        } 
        td { 
         textField id: 'cityField', columns: 20, address.city 
        } 
    td { 
         textField id: 'cityField', columns: 20, address.city 
        } 
       } 
      } 


     scrollPane(id:'scroll',preferredSize: [200,200], constraints: context.CENTER) { 



    panel(layout: new FlowLayout()) { 


     label(icon: imageIcon(new URL('pokemon.png'))) 
    } 


     } 





     } 







     panel(constraints: BorderLayout.SOUTH) { 
      button text: 'Save', actionPerformed: { 
       println address 
label.setIcon('pokemon.png'); 
      } 
     } 

     // Binding of textfield's to address object. 
     bean address, 
      street: bind { streetField.text }, 
      number: bind { numberField.text }, 
      city: bind { cityField.text } 
    } 
} 

Antwort

0

ich mit diesem

@Bindable 
class Address { 
    String street, number, city 
    String toString() { "address[street=$street,number=$number,city=$city]" } 
} 



def address = new Address(street: 'Evergreen Terrace', number: '742', city: 'Springfield') 
    def BL = new BorderLayout() 

def swing = new SwingBuilder() 
def swingBuilder = new SwingBuilder() 
swingBuilder.edt { // edt method makes sure UI is build on Event Dispatch Thread. 


    lookAndFeel 'nimbus' // Simple change in look and feel. 

    frame(title: 'Address', size: [1000, 800], 
      show: true, locationRelativeTo: null, 

      defaultCloseOperation: EXIT_ON_CLOSE) { 

     borderLayout(vgap: 5) 

     panel(constraints: BorderLayout.CENTER, 
       border: compoundBorder([emptyBorder(10), titledBorder('Enter your address:')])) { 
      tableLayout { 

       tr { 
        td { 
         label 'Street:' // text property is default, so it is implicit. 
        } 
        td { 
         textField address.street, id: 'streetField', columns: 20 
        } 
       } 
       tr { 
        td { 
         label 'Number:' 
        } 
        td { 
         textField id: 'numberField', columns: 5, text: address.number 
        } 
       } 
       tr { 
        td { 
         label 'City:' 
        } 
        td { 
         textField id: 'cityField', columns: 20, address.city 
        } 
    td { 
         textField id: 'cityField', columns: 20, address.city 
        } 
       } 
      } 


      scrollPane(id:'scroll',preferredSize: [200,200], constraints: context.CENTER) { 



     panel(layout: new FlowLayout()) { 


    imagelabelx=  label(icon: imageIcon(new URL('pokemon.png'))) 
     } 


      } 





      } 







      panel(constraints: BorderLayout.SOUTH) { 
       button text: 'Save', actionPerformed: { 
        println address 
    imagelabelx.icon= imageIcon(new URL('pokemon2.png')) 
       } 
      } 

      // Binding of textfield's to address object. 
      bean address, 
       street: bind { streetField.text }, 
       number: bind { numberField.text }, 
       city: bind { cityField.text } 
     } 
    } 
lösen
Verwandte Themen