Results 1 to 10 of 10
  1. #1
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Problem with CardLayout

    Hello, i finally made myself a successful jFrame that has a couple of buttons and each button loads new jPanel (cards).

    My problem - if i load card1, witch has some textfield areas, and i input some values in them, then press a button to open card2, then go back to card1 - those values remain.

    Can i make it so each time i press the card switching buttons, they load untouched cards (without any values in textfields that i entered earlier) ?

    I think i need to add something in here:
    Java Code:
       private void Button1ActionPerformed(java.awt.event.ActionEvent evt) {                                                     
           CardLayout card = (CardLayout) displayPanel.getLayout();
           card.show(displayanel, "card1");
        }
    Any suggestions?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Problem with CardLayout

    maybe the easiest way is to create a new instance of "card1" ?!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Problem with CardLayout

    You can give the card a reset() method that blanks out the text fields.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: Problem with CardLayout

    Quote Originally Posted by DarrylBurke View Post
    You can give the card a reset() method that blanks out the text fields.

    db
    Thanks it works!

    made this method
    Java Code:
    private void reset(){
    jLabel1.setText("");
    jTextField1.setText("");
    }
    created a new event "private void formComponentShown" and called the reset method in it.

  5. #5
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: Problem with CardLayout

    Ran into another problem - how do i 'setText' for a ComboBox? is there something similar to settext, like setitem or something?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  7. #7
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: Problem with CardLayout

    i dont really know whats that

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  9. #9
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: Problem with CardLayout

    Sorry, i have no idea what to look for in there.
    I checked the 'how to use comboboxes' section and couldnt find what i need.
    Also there are A LOT of words that i dont even understand what they mean.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem with CardLayout

    Quote Originally Posted by iNko View Post
    Sorry, i have no idea what to look for in there.
    I checked the 'how to use comboboxes' section and couldnt find what i need.
    It's there. Look at the getter and setter methods that the combo box uses in the combobox tutorial and the JComboBox section of the API.

    Also there are A LOT of words that i dont even understand what they mean.
    You will want to keep going through the tutorials and the API, since being able to use them is a skill that gets better with practice, and it will be essential if you are serious about moving forward with your Java education.

    But for the purposes of this forum, if you don't understand anything in the API, then please ask, and we'll be glad to help.

Similar Threads

  1. CardLayout Help
    By David M. in forum New To Java
    Replies: 4
    Last Post: 08-06-2011, 02:57 AM
  2. CardLayout Trouble
    By eLancaster in forum AWT / Swing
    Replies: 2
    Last Post: 06-23-2011, 11:04 AM
  3. Question about cardlayout
    By scheffetz in forum New To Java
    Replies: 1
    Last Post: 04-02-2011, 08:05 PM
  4. Help with CardLayout
    By Kyle227 in forum New To Java
    Replies: 4
    Last Post: 05-28-2010, 01:03 AM
  5. Regarding CardLayout
    By adeeb in forum AWT / Swing
    Replies: 1
    Last Post: 06-07-2008, 07:52 PM

Posting Permissions

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