admin管理员组文章数量:1289528
I'm trying to write a program that uses Java's GridLayout to display a 2x2 set of GIFs. It runs without any errors but the output window I get is blank. The same code works to display a text label or button in a cell, so it seems that the problem is with my use of images.
All the GIF files are under the same src folder as the code, and IntelliJ is able to show them fine when hovering over the filenames -- they just don't show up when the program's run. Not sure where to check for issues.
import java.awt.*;
import javax.swing.*;
public class ShowFlags extends JFrame {
public ShowFlags() {
setLayout(new GridLayout(2, 2, 5, 5));
ImageIcon imgA = new ImageIcon("us.gif");
ImageIcon imgB = new ImageIcon("norway.gif");
ImageIcon imgC = new ImageIcon("uk.gif");
ImageIcon imgD = new ImageIcon("fr.gif");
JLabel jlbA = new JLabel(imgA);
JLabel jlbB = new JLabel(imgB);
JLabel jlbC = new JLabel(imgC);
JLabel jlbD = new JLabel(imgD);
add(jlbA);
add(jlbB);
add(jlbC);
add(jlbD);
}
public static void main(String[] args) {
JFrame frame = new ShowFlags();
frame.setTitle("ShowFlags");
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
本文标签: swingDisplaying GIF files in a Java GridLayoutBlank OutputStack Overflow
版权声明:本文标题:swing - Displaying GIF files in a Java GridLayout - Blank Output - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741463543a2380178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论