JPanel zeigt keinen Inhalt

Lucaaa

Bekanntes Mitglied
Hallo!

Ich möchte JPanels in einer JList anzeigen.
Das Problem ist, das das Panel nur angezeigt wird, wenn ich setPreferredSize() aufrufe.
Hat wer eine Idee warum?

Das Panel:
Java:
public class TileListItem extends JLabel {
 private static final long serialVersionUID = 1L;
 Tile tile;
 
 public TileListItem(Tile tile) {
  this.tile = tile;
  setLayout(new FlowLayout());
  setBackground(Color.blue);
 // setPreferredSize(new Dimension(100, 60));
  add(new JButton("Button"));
  
  // padding
  setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
  
  
  initUI();
 
 }
 
 private void initUI() {
  Box vBox = Box.createHorizontalBox();
  JLabel labColor =new JLabel();
  labColor.setOpaque(true);
  labColor.setBackground(tile.getColor());
  labColor.setPreferredSize(new Dimension(35, 35));
  labColor.setMinimumSize(labColor.getPreferredSize());
  vBox.add(labColor);
  
  String text = "<html>"+
   "<div>"+tile.getTitle()+"</div><br>"+
   "<div>"+tile.getDescription()+"</div>" +
   "</html>";
  
  
  JLabel labText =new JLabel(text);
  vBox.add(labText);
 }
}
 

Zurück
Oben