1

So, I have this BorderLayout frame with a panel pnlLogo in North. In that panel I've got an image in a label. The problem is: I want to put it in the left upper corner of that north. But when I setLayout(null) and setbounds, the image doesn't show at all. In the normal flowlayout it does showup. Anyone who knows why?

package panels.components;

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

public class Logo extends JPanel{
// Declareren
public JLabel lblLogo;

public Logo(){
    // Layout
    this.setLayout(null);
    this.setBackground(Color.decode("#414141"));

    // Logo -> Label
    ImageIcon image = new ImageIcon("src/media/Logo.jpg");
    lblLogo = new JLabel("", image, JLabel.CENTER);

    // Bounds
    lblLogo.setBounds(10, 10, 210, 84);

    // Panel
    this.add(lblLogo);

}

}
Benjamin Naesen
  • 174
  • 1
  • 10
  • possible duplicate of [Using a JPanel with a null layout](http://stackoverflow.com/questions/14982781/using-a-jpanel-with-a-null-layout) – NiematojakTomasz Jan 17 '15 at 22:06

1 Answers1

1

Why don´t you want to use a layout for the panel? If you don´t want the image to fill out the whole frame, you can use

this.setPreferredSize(new Dimension(600, 80));

Make sure you don´t use the absolute layout (setLayout(null)) when using this. Here is a helpful side: click!

monty.py
  • 2,511
  • 1
  • 17
  • 29