我正在嘗試在我的視窗的左上角設定一個圖示。但似乎不起作用..你認為問題出在哪里?我還嘗試在 JLabel 的實體上設定圖示和文本,但只有文本出現。
該鏈接是我制作的 JFrame 輸出的螢屏截圖。

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);
}
}
uj5u.com熱心網友回復:
這是代碼
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();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/323051.html
上一篇:JavaFramesetSize,setLocation不起作用
下一篇:在JPanel中并排創建兩個按鈕
