如何将字符串方法调用到jpanel中

时间:2012-12-10 09:37:24

标签: java swing class for-loop jpanel

如何将方法字符串(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;
}

顺便说一下,这段代码已经很久了

1 个答案:

答案 0 :(得分:2)

假设您要将“printBestillingsordre()”中的视觉文本添加到Panel,最简单的方法是更改​​该行:

info.add(printBestillingsordre());


info.add(new JLabel(printBestillingsordre());

这将创建您的字符串的可视化代表。要组织GUI组件,我建议您查看以下link: