Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the textfield is not visible in frame

I am using Swing framework, and I have one question.

The Address panel is dynamically added to the main frame. I want to call the visible(false) method from the main frame on the Address Panel.

like image 690
krishna Avatar asked Dec 04 '25 00:12

krishna


1 Answers

What you need to do is store the JTextField as a private member of the AddressPanel. And, in AddressPanel, add a method called hideTextField(). Then, in that method call the setVisible(false) method on the private JTextField member.

The code may look similar to the following:

public class AddressPanel {

    private JTextField textFieldToHide;

    public void hideTextField(){
        textFieldToHide.setVisible(false);
    }
}

Then, in the main frame use it like so:

addressPanel.hideTextField();
like image 99
jjnguy Avatar answered Dec 05 '25 12:12

jjnguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!