0
我有一个图形用户界面的建筑来说明一棵树。我扩展的JPanel不显示我在构建JPanel时创建的JLabel。这里是我的JPanel代码:Swing Jlabel没有显示
class NodePanel extends JPanel {
private JLabel content;
NodePanel() {
this.setLayout(new FlowLayout());
this.setBorder(new LineBorder(Color.black));
}
NodePanel(String str) {
this.setLayout(new FlowLayout());
this.setBorder(new LineBorder(Color.black));
content = new JLabel(str);
this.add(content);
}
}
和这里是IM测试它的代码:
NodePanel n1 = new NodePanel(Integer.toString(root.getWeight()));
HuffmanGUI.tp.add(n1);
n1.setBounds((tpWidth/2) - (panelDim/2), vertSpace, panelDim, panelDim);
此代码是在通过一个动作侦听器调用的方法,我知道它的工作原理是因为面板显示在它应该达到的地方,但Jlabel没有显示在里面。为什么会这样呢?
你叫它。不调用revalidate()是问题。 – Bill