Results 1 to 9 of 9
  1. #1
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default Switch JPanels in a single JFrame

    Hi, i'm having some problem in realizing a Frame.. my customer asked me to create a single window (it's a quite big insertion form) in this section of this program and he also asked me to split all the textFields and the ckeckBoxes of this form in 2 or more different panel of the same window, that the user can "slide" with the button "next"...

    The reason is there are too many information to fill in a single big window, so it's better to split the information in more "slidable" panel. The buttons next and back instead, shoud be settled in the bottom of the window and obviously at the 1st "page" the back button is disabled and the same thing for the next button at the last "page".

    So my question is: how can i use the netBeans visual design IDE to make this? Yes i can work on all the single panels i want to split.. but how can i put all of them in the same jFrame at the same coordinates?? is it possible?? and when the next button is clicked do something like this?:

    buttonNextActionPerformed(ActionEvent evt){
    jPanel_N.setVisible(false);
    jPanel_N+1.setVisible(true);
    }

    or maybe you can suggest me other solutions?
    thanx.

    PS: I'm italian, so sorry for my english grammar mistakes..

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Read about CardLayout.

  3. #3
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    Here's another approach to think about:

    Use the designer to lay out a single JPanel, perhaps calling it allTheFields.
    Lay out everything on that one JPanel.
    Then make the panel the contents of a JScrollPane.
    Something vaguely like:
    Java Code:
    ScrollPane appScroll = new JScrollPane(allTheFields, 
    	ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
    	ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    JFrame app = new JFrame();
    app.add(allScroll);
    This way the user can scroll to see a variable subset of the fields.
    And the user is spared the disorientation
    of completely refilling the window with Next or Back.

    Incidentally, I usually use NetBeans to layout a window initially.
    And then find that it is much too rigid, so I write a purpose-build
    LayoutManager that puts things where I want them.
    It usually winds up to be much less work than fighting the NetBeans designer.

  4. #4
    mcashe is offline Member
    Join Date
    Aug 2009
    Posts
    8
    Rep Power
    0

    Default

    I think CardLayout has been deprecated for a while... You may also want to consider a TabbedPane approach.

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    You might want to check out the "Card Layout Actions" entry which makes it easier to use a CardLayout:

    tips4java.wordpress.com/2008/11/01/card-layout-actions

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

    Default

    Quote Originally Posted by mcashe View Post
    I think CardLayout has been deprecated for a while...
    To mcashe: Please back this statement up with facts.

    You may also want to consider a TabbedPane approach.
    To the original poster: while mcashe has a point regarding possible use if JTabbedPane as a way to swap views, please ignore his other "advice" regarding CardLayout. Personally I think that CardLayout is the way to go here.

  7. #7
    mcashe is offline Member
    Join Date
    Aug 2009
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    To mcashe: Please back this statement up with facts.


    To the original poster: while mcashe has a point regarding possible use if JTabbedPane as a way to swap views, please ignore his other "advice" regarding CardLayout. Personally I think that CardLayout is the way to go here.
    My apologies if I offended anyone here. I was speaking from personal experience. I was asked to do a prototype using CardLayout like 6 years ago and if my memory serves me correctly, the only reason I was able to do it was because we were still using like swing 1.1.8 or something like that. I thought it had gone away with that version. I'll look into it.

  8. #8
    mcashe is offline Member
    Join Date
    Aug 2009
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by mcashe View Post
    My apologies if I offended anyone here. I was speaking from personal experience. I was asked to do a prototype using CardLayout like 6 years ago and if my memory serves me correctly, the only reason I was able to do it was because we were still using like swing 1.1.8 or something like that. I thought it had gone away with that version. I'll look into it.
    I took a look and it seems CardLayout is indeed still in use. My apologies. I think my frustrations came with being stuck with swing 1.1.8 when there were so many other cool options out there but were unavailable to me. It appears CardLayout is in the AWT package.

  9. #9
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    I already thought about a JTabbedPane approach, but my boss discard this option.

    However i'm reading documentation about CardLayout... and i think it's really what i need to realize.. i'll test some methods of this class, and i'll let you know if it works or if i have other problems using CardLayout.

    thanks:)

Similar Threads

  1. HELP with jPanels
    By maverik_vz in forum AWT / Swing
    Replies: 1
    Last Post: 03-12-2009, 11:46 AM
  2. Help with overlapping JPanels
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 10:19 PM
  3. Replies: 6
    Last Post: 07-28-2008, 06:04 PM
  4. Can't synchronize multiple JPanels in a JFrame
    By vassil_zorev in forum AWT / Swing
    Replies: 0
    Last Post: 12-30-2007, 04:22 PM
  5. How to add Images to JPanels?
    By Soda in forum New To Java
    Replies: 3
    Last Post: 12-08-2007, 05:54 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
  •