Results 1 to 9 of 9

Thread: Java Visibility

  1. #1
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Java Visibility

    I d like to say hi to everybody before all else.

    My question is about java's visibility option. I have a text field which is called t4 and two radio buttons which are "yes" and "no". When the program gets started "no" is selected as default and I want text field to be invisible while radio button is "no". If the user clicked "yes", that text field should be visible and if clicked "no" , again invisible. How would I do this ? I mean how can I set invisible as default and then , that invisible option would not affect the program until the program is closed. I am using netbeans 6.7.1

    Thanks in advance.. sorry for poor english btw :)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by efozdel View Post
    I d like to say hi to everybody before all else.

    My question is about java's visibility option. I have a text field which is called t4 and two radio buttons which are "yes" and "no". When the program gets started "no" is selected as default and I want text field to be invisible while radio button is "no". If the user clicked "yes", that text field should be visible and if clicked "no" , again invisible. How would I do this ? I mean how can I set invisible as default and then , that invisible option would not affect the program until the program is closed. I am using netbeans 6.7.1

    Thanks in advance.. sorry for poor english btw :)
    Your English is fine, no need to apologize. Put both the 'yes' and 'no' buttons in a ButtonGroup (read the API for that class) and register an ActionListener (read the API documentation again) for both buttons; if the 'yes' button is selected set your component to visible, if the 'no' button is selected (the 'yes' button is not selected in that case bcause of that ButtonGroup object)) set your component to invisible.

    kind regards,

    Jos

  3. #3
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    If i guess right you wish to set the textfield "editable" and not "visible" when user chooses "yes" ..you can do as jTextField.setEditable(false/true);
    The Quieter you become the more you are able to hear !

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    I thought invisible meant that the component was not present in the container. IE it could not be seen.
    That would require removing it and adding it.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Norm View Post
    I thought invisible meant that the component was not present in the container. IE it could not be seen.
    That would require removing it and adding it.
    That's not true: an invisible component can still be present in the container (the parent component); it is just not visible. There's no need to add/remove it when you want to make it in/visible.

    kind regards,

    Jos

  6. #6
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    I actually grouped those radio buttons, "Yes" and "No". My problem is when the program gets started, I want t4 (textfield) to be invisible (it should not be shown in the program). when "yes" is selected, t4 becomes visible. When t4 's default visibility is true, program works well but after changing its default values to false , that text field never comes to program again. Thanks for answers ..

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    Do you revalidate t4's parent container after changing the visibility?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    efozdel is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default

    no , I didnt do anything .. how would I do that ?

  9. #9
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    maybe cardlayout would be easier to try first for you. check out the sun tutorials, if not, then whatever t4's container name is do this,

    (imaginary name I am giving t4's container name is panel.....)
    Java Code:
    panel.validate();

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2009, 06:39 AM
  2. Newbie help on visibility and static final
    By tornado in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 02:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •