所以我使用Eclipse與Windows生成器。我只是想知道,如果有反正我可以導入一個圖像,將顯示在JFrame上,我可以輕鬆地移動和重新大小,而不是設置位置和大小,並繪製它。將圖像添加到JFrame
8
A
回答
14
有在Swing沒有提供專門的圖像組件(這是悲傷在我看來)。所以,有幾個選項:
- 作爲@Reimeus說:使用帶圖標的JLabel。
在窗口構建器中創建一個JPanel,它將表示圖像的位置。然後使用幾行代碼將您自己的自定義圖像組件添加到JPanel中,您將永遠不必更改這些代碼。他們應該是這樣的:
JImageComponent ic = new JImageComponent(myImageGoesHere); imagePanel.add(ic);
其中JImageComponent是延伸
JComponent
,它覆蓋paintComponent()
方法繪製圖像的自我創建的類。
+1
@Downvoter:小心點評? –
14
這裏是添加圖片到JFrame
的一個簡單的例子:
frame.add(new JLabel(new ImageIcon("Path/To/Your/Image.png")));
2
如果您使用Netbeans進行開發,請使用jLabel並更改它的圖標屬性。
相關問題
- 1. 將圖像添加到jframe
- 2. 將圖像添加到JFrame
- 3. 無法將圖像添加到JFrame?
- 4. 將圖標點擊添加到JFrame
- 5. 試圖將多個JPanel添加到JFrame
- 6. 如何將圖標添加到JFrame中
- 7. 將Jpanel添加到JFrame?
- 8. 將JPanel添加到JFrame中
- 9. 將類添加到JFrame中
- 10. 將JScrollPane添加到JFrame中
- 11. 將JList添加到JFrame
- 12. 將jpanel添加到jframe
- 13. 將JApplet添加到JFrame中
- 14. 將JPanel添加到JFrame中
- 15. 將JLabel添加到JFrame中
- 16. 將圖像添加到JFrame中現有的JPanel中
- 17. 使用Swing將背景圖像添加到JFrame
- 18. 如何將圖像添加到JFrame項目
- 19. 使用JLabel將背景圖像添加到JFrame
- 20. 在JPanel上繪製圖像並將其添加到JFrame
- 21. 添加圖像在JFrame中:Java的
- 22. 添加圖像時JFrame不起作用
- 23. 將圖像添加到GUI
- 24. 將圖像添加到TextField
- 25. 將圖像添加到Tkinter
- 26. 將圖像添加到HighChart
- 27. 將圖像添加到jsfiddle
- 28. 將圖像添加到JSfiddle
- 29. 將圖像添加到GridView
- 30. 將圖像添加到GUI
添加圖像到'JLabel' – Reimeus
這是一個好主意,謝謝你。 – user2612619