简体   繁体   中英

Set jTextArea to visible false by default

I am making an application that show the information I entered in a textfield, combo box, etc.. into a text area.

I want to hide the text area when I started up the application and when I press on a button I want to show with the desired information.

I've tried to place <nameOfTextArea>.setVisible(false); in the frame constructor, but it is still visible.

How can I start up the frame without seeing this text area?

Constructor frame:

public StudentInfoFrame() {

    initComponents();

    textAreaVoorOpslaanInfo.setVisible(false);

}

My button in the frame:

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);
    }

}

My question is solved. The jTextArea was invisible, but the jScrollPane was not.

Made the jScrollPane invisible in the constructor and it worked as intended.

Thanks for the help from the people above this post.

Call JComponent#revalidate() on parent component after changing element's visibility.

Call JFrame#setVisible(true) in the end after adding all the components.

Try this one:

textAreaVoorOpslaanInfo.hide(); 

or this:

textAreaVoorOpslaanInfo.show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM