[英]JPanel does not show up inside another JPanel
class ABC extends JFrame {
public JPanel createGUI()
{
JPanel outerPanel = new JPanel();
outerPanel.setLayout(null);
JLabel top = new JLabel();
top.setBounds(40,40,400,30);
top.setText("Hello World");
outerPanel.add(top);
int l = getLength();
JPanel innerPanel = new JPanel();
if(l==0)
{
innerPanel.setLayout(null);
JLabel empty = new JLabel("No Data Found");
empty.setBounds(80,150,300,30);
innerPanel.add(empty);
}
else
{
innerPanel.setLayout(new GridLayout(l,4,5,5));
for(int i=0;i<l;i++)
{
innerPanel.add(new JLabel("Text1");
innerPanel.add(new JLabel("Text2");
JButton b1 = new JButton("Button1");
innerPanel.add(b1);
JButton b2 = new JButton("Button2");
innerPanel.add(b2);
}
}
outerPanel.add(innerPanel);
return outerPanel;
}
}
在上面的代码中,innerPanel没有显示出来,也没有任何错误发生。任何想法如何显示位于externalPanel内部的innerPanel。我尝试使用getContentPane()。add(innerPanel),但是没有用。
尝试改变
outerPanel.setLayout(null);
至
outerPanel.setLayout(new FlowLayout());
或完全删除setLayout调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.