mr_bemar 0 Newbie Poster

Hi,

I want to load a simpel image into a JPanel.
I use the following way:

public class MyClass{
 private Icon Bild = new ImageIcon("http://today.java.net/jag/old/green/duke/T4.gif");
    JLabel jLabel2 = new JLabel(Bild);

private void init (){
  jLabel2.setBackground(Color.white);
        jLabel2.setForeground(Color.white);
        jLabel2.setBorder(BorderFactory.createEtchedBorder());
        jLabel2.setPreferredSize(new Dimension(100, 70));
        jLabel2.setIconTextGap(0);
        jLabel2.setLabelFor(contentPane);
        jLabel2.setIcon(Bild);
}
}

I think the code is correct but the image doesn't appear.
Do anyone recognize my bug?

Thanks in advance

Greetings
Ben

Heres the complete class:

################# Beginn Class ####################
package whproject;

import java.awt.BorderLayout;
import java.awt.Dimension;

import java.awt.*;
import java.util.Date.*;
import java.util.Date;
import javax.swing.*;
import javax.swing.border.TitledBorder;

/**
 * <p>Title: World-Hotel Checker</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 *
 * @author not attributable
 * @version 1.0
 */
public class MainFrame extends JFrame{
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();

    TitledBorder titledBorder1 = new TitledBorder("");
    TitledBorder titledBorder2 = new TitledBorder("");

    private JLabel jLabel1 = new JLabel();
    private Icon Bild = new ImageIcon("http://today.java.net/jag/old/green/duke/T4.gif");
    JLabel jLabel2 = new JLabel(Bild);

    public MainFrame() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        jLabel2.setBackground(Color.white);
        jLabel2.setForeground(Color.white);
        jLabel2.setBorder(BorderFactory.createEtchedBorder());
        jLabel2.setPreferredSize(new Dimension(100, 70));
        jLabel2.setIconTextGap(0);
        jLabel2.setLabelFor(contentPane);
        jLabel2.setIcon(Bild);
        jPanel1.add(jLabel1);
        jPanel1.add(jLabel2);
        jLabel1.setPreferredSize(new Dimension(200, 20));
        jLabel1.setText("Prüfe Website ....");
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(borderLayout1);
        this.setResizable(false);
        setSize(new Dimension(211, 150));
        setTitle("World-Hotel Checker");
        contentPane.add(jPanel1, java.awt.BorderLayout.CENTER);
    }

    public void AddTextToTextfield(String content){
        jLabel1.setText(content);
    }

    public void AddPicToScrollPane(){
    }

}
#################### end class ####################
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.