Results 1 to 7 of 7
  1. #1
    Aggror is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default show panel when button clicked

    I have been practising around with Java desktop appplications. At the moment I have a main form with a button. When I click this button I want a jpanel form to open which I already made.

    I am inside the button Clicked event but I can not find out how to show this panel/form.

    Do I need to call the form object and use a method or is it something more complicater?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

    Default

    Check out CardLayout.

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default

    Aggror,

    The description of what exacly you want is very vague, can you please elaborate.

    Regards.

  4. #4
    Aggror is offline Member
    Join Date
    Sep 2010
    Posts
    4
    Rep Power
    0

    Default

    Sorry about that, I thought it was clear enough.

    I have created a new Java desktop application.
    Inside the main form I dragged this button.
    I have also created a new JPanel form. (via add --> new --> JPanel form)
    My question is how can I display this JPanel form when I press the button on the main form.

    I was thinking about child forms or jpanel1.display or show() but sofar no luck.

    I hope this explanation is better.

    @ Kevin. Thanks for your answer. When I get home I''l download that project to see if I can use it.

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

    Default

    OP, I assume that your GUI was created using a drag-and-drop GUI builder such as NetBeans' or something similar. What you should strongly consider is avoid using such tools for now, but instead go to the Swing tutorials and use them to learn to hand-code your Swing apps. The knowledge gained will help immensely should you continue to hand-code your Swing apps or if you decide to go back to your drag and drop GUI builders.

    Luck.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

    Default

    Quote Originally Posted by Aggror View Post
    I have also created a new JPanel form. (via add --> new --> JPanel form)
    ...
    I was thinking about child forms or jpanel1.display or show() but sofar no luck.
    Yikes. I'd recommend ditching the GUI builder and coding it by hand. You'll save yourself quite a few headaches in the long run.

    Quote Originally Posted by Aggror View Post
    My question is how can I display this JPanel form when I press the button on the main form.
    Yep, still sounds like CardLayout to me. Unless you want it to pop up in a new window: then check out JDialog.

    Quote Originally Posted by Aggror View Post
    @ Kevin. Thanks for your answer. When I get home I''l download that project to see if I can use it.
    Huh? CardLayout is a part of the standard Java API. You shouldn't have to download anything extra for it.

  7. #7
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default

    Aggror,

    Given your last post I presume you are using a GUI editor, something not everyone uses (Myself included). If this is the case then can you please provide further details so people can help you better.

    Edit - Beaten again. But I agree with the above, ditch the drag-and-drop editors and write your own code. Not only will it save you headaches as KevinWorkman pointed out, but you will learn so much more.

    Regards.
    Last edited by Ronin; 10-14-2010 at 05:08 PM.

Similar Threads

  1. Replies: 4
    Last Post: 08-11-2010, 01:47 PM
  2. Replies: 0
    Last Post: 04-28-2010, 02:39 PM
  3. Replies: 4
    Last Post: 02-16-2009, 04:20 PM
  4. Replies: 11
    Last Post: 02-13-2009, 01:52 PM
  5. Display success message in same page when submit button is clicked
    By am17mu in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 11:56 AM

Tags for this Thread

Posting Permissions

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