java - ImageIcon 没有出现在 JLabel 或 JButton 上
问题描述
我想穿上or ,但它没有出现在程序上Image
。JButton
JLabel
import javax.swing.*;
public class JButtonEx extends JFrame{
JButtonEx() {
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(new ImageIcon("network/star.png"));
add(label);
setVisible(true);
}
public static void main(String[] args) {
new JButtonEx();
}
}
解决方案
推荐阅读
- c# - 未找到 SendGridAPIClient
- javascript - 如何将带有嵌入对象的对象从 JavaScript (jQuery/ajax) 传递到 Python (Flask)?
- java - openapi 代码生成器 - 使用 @Digits 代替 @DecimalMax / @DecimalMin
- java - 使用 Dagger2 和 MVVM 避免应用程序类的静态上下文
- bash - 当我在 Ubuntu 上打开终端时,总是显示一行
- c++ - 逼近非常大数的二项式系数的对数
- java - 如何将日期和时间字符串转换为时间前类型?
- c++ - min 的最佳实现是什么?
- node.js - 如何确保 Lambda 函数等待调用带有 await 的异步函数?
- javascript - 如何替换列表中每个字母的第一次出现?