您好,我無法將圖像添加到Groovy中的GUI標籤。任何人都可以幫助我能夠做到這一點的代碼?我到處搜索並沒有找到答案。我正在努力完成一個無法想象的項目。將圖像添加到Groovy的GUI中
我使用SwingBuilder創建我的GUI 這裏是我曾嘗試:
// add a text panel
def mainPanel = {
sB.panel(layout : new BorderLayout(), background: java.awt.Color.LIGHT_GRAY){
label(text: 'Welcome to your closet', horizontalAlignment: JLabel.CENTER,
constraints : BorderLayout.CENTER, icon: ImageIcon('/home/*****/Documents/ComputerScience/CS315/icons/create.png'))
buttonPanel()
}
}
我得到的錯誤是:
Caught: groovy.lang.MissingMethodException: No signature of method: GUI.ImageIcon() is applicable for argument types: (java.lang.String) values: [/home/*****/Documents/ComputerScience/CS315/icons/create.png]
groovy.lang.MissingMethodException: No signature of method: GUI.ImageIcon() is applicable for argument types: (java.lang.String) values: [/home/*****/Documents/ComputerScience/CS315/icons/create.png]
at GUI$_closure11_closure119.doCall(ClosetGUI.groovy:888)
使用以下修正:
label(text: 'Welcome to your closet', horizontalAlignment: JLabel.CENTER,
constraints : BorderLayout.CENTER, icon: imageIcon(resource: '/home/*****/Documents/ComputerScience/CS315/icons/create.png'))
buttonPanel()
我收到以下錯誤:
Caught: java.lang.RuntimeException: Failed to create component for 'imageIcon' reason: java.lang.RuntimeException: In imageIcon the value argument 'null' does not refer to a file or a class resource
java.lang.RuntimeException: Failed to create component for 'imageIcon' reason: java.lang.RuntimeException: In imageIcon the value argument 'null' does not refer to a file or a class resource
at GUI$_closure11_closure119.doCall(ClosetGUI.groovy:888)
任何幫助將是驚人的 謝謝!
你可以張貼一些代碼?你在使用GroovyFX嗎?搖擺? SwingBuilder?你有什麼嘗試?你得到的錯誤是什麼? – 2013-05-09 00:32:37
抱歉,我正在使用SwingBuilders,現在我將發佈代碼! – ola 2013-05-09 00:40:13
你應該使用小寫的imageIcon,而不是大寫的ImageIcon。 – 2013-05-09 00:45:40