[英]Hi! setting ImageIcon to a Jframe and other component dont seem to work. I need help pls
我正在嘗試為我的 Window 在左上角設置一個圖標。但似乎沒有用。您認為問題出在哪里? 我還嘗試在 JLabel 的實例上設置圖標和文本,但只有文本出來了。
鏈接是我做的JFrame的output的截圖。
public class Window extends JFrame{
private final int WIDTH = 600;
public Window(){
// Setting the Window
setTitle("Module Organizer");
ImageIcon img = new ImageIcon("checkmark-square.png");
setIconImage(img.getImage());
setSize(WIDTH,(WIDTH*3)/4);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// adding components
add(new NavPane(), BorderLayout.WEST);
setVisible(true);
}
}
這是代碼
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JLabel;
public class Window{
JFrame f=new JFrame("Test");
public Window(){
JPanel j=new JPanel();
f.setSize(1000,500);
ImageIcon img = new ImageIcon("Image.jpg");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel l=new JLabel(img);
j.add(l);
f.add(l);
f.setVisible(true);
}
public static void main(String[] args) {
new Window();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.