如何将方法字符串(printBestillingsordre)调用到另一个方法并为其创建JPanel
public String printBestillingsordre(){
JButton button = new JButton("Varemodtaget");
String temp = "";
for(HentbestillingsordreRegistrer hentboregistrer: hbor){
if(status == "Leveret"){
temp += "Bestillings Status: " + hentboregistrer.BestillingsStatus+" \n" +
"LeverandoerID: "+ hentboregistrer.LeverandoerID+" \n";
}else{
temp += hentboregistrer.BestillingsStatus+ button + "\n" +
"LeverandoerID: "+ hentboregistrer.LeverandoerID+" \n";
}
System.out.println(temp);
}
return temp;
}
进入此代码
public JPanel HentOrdreGUI(){
JPanel info = new JPanel();
info.setLayout(new BorderLayout());
info.add(printBestillingsordre());
return null;
}
顺便说一下,这段代码已经很久了
答案 0 :(得分:2)
假设您要将“printBestillingsordre()”中的视觉文本添加到Panel,最简单的方法是更改该行:
info.add(printBestillingsordre());
要
info.add(new JLabel(printBestillingsordre());
这将创建您的字符串的可视化代表。要组织GUI组件,我建议您查看以下link: