il JPanel viene disposto nel JTabbedPane, il quale di default cercherà di far occupare ai suoi componenti tutto lo spazio a disposizione (mi correggano se sbaglio). Per cui dovresti fare una cosa del genere
codice:
import javax.swing.*;
import java.awt.*;
class myPanel extends JPanel {
JLabel background;
private String path;
protected ImageIcon getImageIcon(String path) {
try {
java.net.URL imgURL = new java.net.URL(path);
ImageIcon icon = new ImageIcon(imgURL);
return icon;
}
catch (Exception e) {
System.out.println("Image not found!");
return null;
}
}
public JLabel getLabel() {
return background;
}
public myPanel(String path) {
super();
this.path = path;
background = new JLabel(getImageIcon(path));
this.add(background);
}
}
public class nullLayoutDemo extends JFrame {
JTabbedPane tPane;
myPanel panel;
public nullLayoutDemo() {
super("Demo con i Tabbed Pane");
this.setSize(600, 400);
this.getContentPane().setLayout(new BorderLayout());
JLabel credits = new JLabel("Creato da Andrea");
this.getContentPane().add(credits, BorderLayout.SOUTH);
tPane = new JTabbedPane();
JPanel comodo = new JPanel();
comodo.setLayout(null);
panel = new myPanel("http://www.google.it/logos/olympics06_ski_jump.gif");
panel.setBounds(40, 50, panel.getLabel().getIcon().getIconWidth(),panel.getLabel().getIcon().getIconHeight());
comodo.add(panel);
tPane.addTab("Google Panel", comodo);
this.getContentPane().add(tPane, BorderLayout.CENTER);
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main (String[] args) {
nullLayoutDemo demo = new nullLayoutDemo();
}
}