【发布时间】:2014-04-28 18:51:12
【问题描述】:
我有一个“主”面板。我想在主面板中有一个“侧面”面板。侧面由另外两个面板组成,我们称之为一个图形面板和一个支持面板。我正在尝试将标签从主标签添加到 SupportPanel,但没有发生任何变化。
这是我的侧面板:
public class LateralSupportPane extends JPanel{
private final static int WIDTH = 240;
private final static int HEIGHT = 740;
private GraphicPanel gp;
private SupportPanel sp;
public LateralSupportPane(){
this.gp = new GraphicPanel();
this.sp = new SupportPanel();
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
this.setLayout(new GridLayout(2, 1));
//this.setBorder(BorderFactory.createLineBorder(Color.black));
this.add(gp);
this.add(sp);
this.setVisible(true);
}
public void addLabel(String label){
sp.addLabel(label);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
gp.paintComponent(g);
}
public void addLabel(String label){
sp.addLabel(label);
}
这是我的支持面板:
public class SupportPanel extends JPanel{
private JLabel label;
private final static int WIDTH = 240;
private final static int HEIGHT = 370;
public SupportPanel(){
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
label = new JLabel();
label.setText("<html>BlaBla</html>");
this.setLayout(new GridLayout(10, 1));
this.add(label);
this.setVisible(true);
}
public JLabel getLabel() {
return label;
}
public void addLabel(String text){
JLabel label = new JLabel(text);
if(this.getComponentCount() < 10){
this.add(label);
} else {
this.remove(0);
this.add(label);
}
}
我从主面板调用侧面板的 addLabel。
编辑:这是所有面板的框架。板本身是添加到框架中的面板。该板还有另一个面板,即黑色矩形和字符串所在的区域。然后侧面板由另外 2 个面板组成,GraphicPanel(黑色矩形)和 supportPanel,这是我想要放置标签的区域。
验证所有面板没有任何进展。
【问题讨论】: