簡體   English   中英

默認情況下,將jTextArea設置為可見的false

[英]Set jTextArea to visible false by default

我正在創建一個應用程序,將我在文本字段,組合框等中輸入的信息顯示在文本區域中。

我想在啟動應用程序時隱藏文本區域,當我按下我想要顯示所需信息的按鈕時。

我試過放置<nameOfTextArea>.setVisible(false); 在框架構造函數中,但它仍然可見。

如何在不看到此文本區域的情況下啟動框架?

構造函數框架:

public StudentInfoFrame() {

    initComponents();

    textAreaVoorOpslaanInfo.setVisible(false);

}

我在框架中的按鈕:

private void uitvoerButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              

    try{
        ..... Variables here .....

        textAreaVoorOpslaanInfo.setVisible(true);
        textAreaVoorOpslaanInfo.append("Voornaam: \t\t" + voornaam + "\n"
                                       + "Achternaam: \t\t" + achternaam + "\n"
                                       + "E-mail adres: \t\t" + email + "\n"
                                       + "Geboortedatum: \t" + geboortedatum + "\n"
                                       + "Lengte: \t\t" + lengte + "m\n"
                                       + "Gewicht: \t\t" + gewicht + "kg\n"
                                       + "Geslacht: \t\t" + geslacht + "\n"
                                       + "Vooropleiding(en): \t" + vooropleiding + "\n"
                                       + "Uitwonend: \t\t" + uitwonend);

    } catch (Exception e){
        System.out.println(e);
    }

}

我的問題解決了。 jTextArea是不可見的,但jScrollPane不是。

使jScrollPane在構造函數中不可見,並且按預期工作。

感謝這篇文章以上人員的幫助。

在更改元素的可見性后,在父組件上調用JComponent#revalidate()

在添加所有組件后,最后調用JFrame#setVisible(true)

試試這個:

textAreaVoorOpslaanInfo.hide(); 

或這個:

textAreaVoorOpslaanInfo.show();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM