簡體   English   中英

我正在嘗試在我的 gui 中放置一個 imageicon,但是當我運行代碼時它沒有出現。 有人可以告訴我如何解決它

[英]I am trying to put an imageicon in my gui but it doesn't appear when I run the code. Can somebody tell me how to fix it

這是我現在正在使用的代碼。 當我運行代碼時,圖像不顯示。

import javax.swing.*;
import java.awt.*;

public class Interface {

    private static JLabel name;
    private static ImageIcon image = new ImageIcon("DigiD.png");

    public static void main(String[] args) {
        //Panel
        JPanel panel = new JPanel();
        panel.setBackground(new Color(255, 145, 77, 255));

        //Titel van de app
        name = new JLabel("Food 4 U");
        name.setFont(new Font("Gill Sans Ultra Bold", Font.BOLD, 20));
        name.setBounds(135, 1, 1000, 50);

        JLabel logo = new JLabel(image);
        panel.add(logo);

        //Frame
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(true);
        frame.setSize(400, 1000);
        frame.getContentPane().setBackground(new Color(255, 145, 77, 255));
        frame.add(panel);

        frame.setVisible(true);

    }
}

對我來說很好。 確保圖像位於項目的正確文件夾中。 (直接在帶有整個項目名稱的頂級文件夾內)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM