如何將影象新增到JPanel? - How to add an image to a JPanel?
問題:
I have a JPanel to which I'd like to add JPEG and PNG images that I generate on the fly. 我有一個JPanel ,我想向其中新增即時生成的JPEG和PNG影象。
All the examples I've seen so far in the Swing Tutorials , specially in the Swing examples use ImageIcon
s. 到目前為止,我在Swing教程中看到的所有示例,特別是在Swing示例中,都使用ImageIcon
。
I'm generating these images as byte arrays, and they are usually larger than the common icon they use in the examples, at 640x480. 我將這些影象生成為位元組陣列,它們通常比示例中使用的通用圖示大,尺寸為640x480。
- Is there any (performance or other) problem in using the ImageIcon class to display an image that size in a JPanel? 使用ImageIcon類在JPanel中顯示該大小的影象時是否存在任何(效能或其他)問題?
- What's the usual way of doing it? 通常的做法是什麼?
- How to add an image to a JPanel without using the ImageIcon class? 如何不使用ImageIcon類將影象新增到JPanel?
Edit : A more careful examination of the tutorials and the API shows that you cannot add an ImageIcon directly to a JPanel. 編輯 :對教程和API的更仔細的檢查表明,您不能將ImageIcon直接新增到JPanel。 Instead, they achieve the same effect by setting the image as an icon of a JLabel. 而是通過將影象設定為JLabel的圖示來實現相同的效果。 This just doesn't feel right... 只是感覺不對...
解決方案:
參考一: https://stackoom.com/question/1FuZ參考二: How to add an image to a JPanel?
- 前端講設計模式-職責鏈真的是你理解的那樣嗎?
- 在 Python 中將 datetime.date 轉換為 UTC 時間戳 - Converting datetime.date to UTC timestamp in Python
- IIS 7.5上的ASP.NET MVC - ASP.NET MVC on IIS 7.5
- 如何將影象新增到JPanel? - How to add an image to a JPanel?
- 在 R 和 RStudio 中清除控制檯的功能 - Function to clear the console in R and RStudio
- 如何向 NSDate 新增 1 天? - How do I add 1 day to an NSDate?
- 如何從生成器或列表中獲取前 N 個專案? [複製] - How to take the first N items from a generator or list? [duplicate]
- 在 PHP 中將一種日期格式轉換為另一種格式 - Convert one date format into another in PHP
- 在另一個 html 表單中包含一個 html 表單是否有效? - Is it valid to have a html form inside another html form?
- Double 與 BigDecimal? - Double vs. BigDecimal?
- 如何告訴 Gradle 使用特定的 JDK 版本? - How do I tell Gradle to use specific JDK version?
- 重新命名 MySQL 中的列 - Rename a column in MySQL
- numpy.array 形狀 (R, 1) 和 (R,) 之間的區別 - Difference between numpy.array shape (R, 1) and (R,)
- 如何在 JSON 中轉義雙引號 - How to escape double quotes in JSON
- 如何使用 JavaScript 獲取整個文件的高度? - How to get height of entire document with JavaScript?
- numpy.random.seed(0) 有什麼作用? - What does numpy.random.seed(0) do?
- 在HTML5中檢測iPad Mini - Detect iPad Mini in HTML5
- 如何將引數傳遞給 addEventListener 偵聽器函式? - How to pass arguments to addEventListener listener function?
- node.js 雜湊字串? - node.js hash string?
- Windows 7 SDK 安裝失敗 - Windows 7 SDK installation failure