-4

I have a problem because I want to put a small JPanel inside a different JPanel, but I can't get the small JPanel to show.

What am I missing?

    this.setLayout(new BorderLayout(5,5));

    this.cardsPanel= new JPanel();
    this.cardsPanel.setBackground(Color.DARK_GRAY);
    this.cardsPanel.setLayout(new FlowLayout (FlowLayout.CENTER,3,10));

    this.cardsPanel2= new JPanel();
    this.cardsPanel2.setBackground(Color.DARK_GRAY);
    this.cardsPanel2.setLayout(new FlowLayout (FlowLayout.CENTER,3,10));

    this.tablePanel=new JPanel();
    this.tablePanel.setBackground(Color.PINK);
    this.tablePanel.setLayout(new FlowLayout (FlowLayout.CENTER,5,5));

    this.tablePanel1=new JPanel();
    this.tablePanel1.setBackground(Color.ORANGE);
    this.tablePanel1.setPreferredSize(new Dimension(100,100));
   // this.tablePanel1.setLayout(null);
    this.tablePanel1.add(tablePanel);

    this.add(cardsPanel, BorderLayout.SOUTH);
    this.add(cardsPanel2, BorderLayout.NORTH);
    this.add(tablePanel,BorderLayout.CENTER);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

1

Using that code:

  • Neither cardsPanel1 nor cardsPanel2 (dark gray) have any components (or therefore) any size. At 0x0 pixels size, they are invisible even when added to another container (unless the layout stretches them).
  • tablePanel (pink) should be visible so long as this is assigned enough space in whatever layout it is added to.
  • tablePanel1 (orange) should not be visible as it is never added to anything.

But as mentioned, for better help sooner, post an MCVE (Minimal Complete and Verifiable Example).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

this.validate(); your root panel after adding new content.

T.G
  • 1,913
  • 1
  • 16
  • 29