public static void main(String[] args) throws IOException { JFrame frame = new JFrame("demo"); JPanel panel = new JPanel(); JLabel label = new JLabel(); label.setIcon(new ImageIcon("D:\\Deeplearn\\data\\nv.jpg")); panel.add(label); //多图多label JLabel label1 = new JLabel(); label1.setIcon(new ImageIcon("D:\\Deeplearn\\data\\nv.jpg")); panel.add(label1); frame.add(panel); //自适应窗口? frame.pack(); //设置窗口可见,构造初始化是不可见的 frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
效果: