Results 1 to 5 of 5
  1. #1
    beginnerprog is offline Member
    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Default when i click on Jbutton i want one jpanel to disappear and another to appear

    when i click on a button moneyButton, im trying to make it so the timePanel disappears and is replaced by a moneyPanel.
    Also before any button is clicked the timePanel is visible. when i click on the timeButton i just made components visible, however i cant do this for the moneyButton hence ive created a new JPanel which i want to make visible. However i cant make this happen.
    heres some of my code, msg me if you want to see all of it.

    Java Code:
    JPanel moneyPanel = new JPanel();
    	  moneyPanel.setVisible(true);
    	  JComboBox priceairportbox = new JComboBox(Airport);
    	  moneyPanel.setBackground(Color.BLUE);
    	  moneyPanel.setPreferredSize(new Dimension(320, 240));
    	  moneyPanel.add(priceairportbox);
    	  priceairportbox.setVisible(true);
    Java Code:
    actionmoneybutton clicktime = new actionmoneybutton();
    	  moneyButton.addActionListener(clicktime);


    Java Code:
     public class actionmoneybutton implements ActionListener{
    	  public void actionPerformed(ActionEvent clicktime){
    	  
    	  
          
    	   timePanel.setVisible(false);
    	   moneyPanel.setVisible(true);
    	  
    
    	  
    	  
    	  }
    	  }
    Last edited by beginnerprog; 03-17-2013 at 09:13 PM.

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

    Default Re: when i click on Jbutton i want one jpanel to disappear and another to appear

    If this were my project, I'd look into using a CardLayout to help me swap views. For example: Notifying a cardlayout manager from within a custom Panel
    Last edited by Fubarable; 03-17-2013 at 09:29 PM.

  3. #3
    beginnerprog is offline Member
    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Default Re: when i click on Jbutton i want one jpanel to disappear and another to appear

    Quote Originally Posted by Fubarable View Post
    If this were my project, I'd look into using a CardLayout to help me swap views. For example: Notifying a cardlayout manager from within a custom Panel
    is there any way i can do this with the current layout manager?

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

    Default Re: when i click on Jbutton i want one jpanel to disappear and another to appear

    Quote Originally Posted by beginnerprog View Post
    is there any way i can do this with the current layout manager?
    What do you have against CardLayout? It doesn't bite.

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

  5. #5
    beginnerprog is offline Member
    Join Date
    Mar 2013
    Posts
    22
    Rep Power
    0

    Default Re: when i click on Jbutton i want one jpanel to disappear and another to appear

    Thanks for the help guys lol back to square one, need to start again and use more than one class =(

    Programming hurts me lol

Similar Threads

  1. JButton after a click
    By tnrh1 in forum AWT / Swing
    Replies: 9
    Last Post: 12-09-2011, 12:45 AM
  2. JButton click
    By mine0926 in forum New To Java
    Replies: 0
    Last Post: 07-30-2010, 04:50 AM
  3. JButton click problem
    By mine0926 in forum NetBeans
    Replies: 7
    Last Post: 06-11-2010, 03:00 AM
  4. JButton doesn't disappear when it is supposed to?
    By ecliptical in forum New To Java
    Replies: 4
    Last Post: 01-25-2010, 12:41 AM
  5. How to make a JButton disappear?
    By diab01ical in forum New To Java
    Replies: 2
    Last Post: 06-04-2008, 02:48 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
  •