我正在尝试在 JLabel 中添加图像,但它不起作用。第二个标签有效,但第一个 JLabel 无效。这是代码。提前致谢。
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MainLabel {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame jframe;
jframe = createFrame();
ImageIcon ii = new ImageIcon("images.jpeg");
JLabel label = new JLabel(ii);
jframe.add(label);
Label label123 = new Label("Be Nice to World!!");
jframe.add(label123);
jframe.setVisible(true);
}
static JFrame createFrame() {
JFrame guiFrame = new JFrame();
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiFrame.setTitle("BorderLayout Example");
guiFrame.setSize(700, 300);
return guiFrame;
}
}