いくつかの JLabel を保持する JPanel サブクラスを作成したいと考えています。コードを書き始めましたが、すぐに大きな問題が見つかりました。JPanel サブクラスに追加されたコンポーネントが表示されない (または JPanel に追加されていない)。JPanel サブクラスのコードは次のとおりです。
public class ClientDetails extends JPanel
{
private JLabel nameAndSurname = new JLabel ("Name & Surname");
private JLabel company = new JLabel ("Company");
private JPanel topPanel = new JPanel ();
public ClientDetails ()
{
this.setBackground(Color.white);
this.setLayout(new BorderLayout());
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
topPanel.add(nameAndSurname);
topPanel.add(company);
this.add(topPanel,BorderLayout.PAGE_START);
}
}