Results 1 to 10 of 10
  1. #1
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default About Forms Properties

    Hi,

    I have a form called frmMain i want this form to be a parent form. Then I created 2 button (button1 and button2). When button1 is click I want another form to show this if an internal form (a MDI child). then When button2 is click I want form2 (another MDI Child) to show and go on top of form1.
    my questions are:

    1. Is this the right way to make Parent and Child forms in java?
    2. How can I set form on top of another form?
    3. How can I divide the form? What I am trying to do is on main form's (parent form) left side is an internalform or frame and inside that is buttons. On the right side of Main form is Internal Form/s that shows and uload depends on the users click on buttons on left side.

    Thanks and Sorry if my english is bad,
    geje
    Last edited by mine0926; 04-29-2010 at 09:36 AM.

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

    Default

    Will CardLayout help?

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I do not know how to do CardLayout... It is not in the properties and when I type ".cardlayout" it show nothing.

    Thanks for your reply.

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I found CardLayout. Now I am trying to work with it. From class frmMain I declare CardLayout.

    Java Code:
          public class frmMain extends java.awt.Frame{
               CardLayout cl = new CardLayout();
    then set some properties base on this site:http://www.java-tips.org/java-se-tip...ardlayout.html

    Java Code:
          public frmMain() 
            {
                initComponents();
                this.setExtendedState(MAXIMIZED_BOTH);
                LeftFrame.setSize(LeftFrame.getWidth(), this.getHeight()); //The Left part of the JFrame    
                jPanel1.setSize(this.getWidth() - LeftFrame.getWidth(), this.getHeight() - LeftFrame.getHeight());
                jPanel1.setLayout(cl);        //HERE
                jPanel1.add(frmMaterials, 1); //HERE -- I try frmMaterials as a JPanel and Internal Frame component, I also try the index as string ("1") and as Integer (1)
                jPanel1.add(frmCustomer, 2);  //HERE -- I try frmCustomer as a JPanel and Internal Frame component
            }
    And here is the code when user click the button

    Java Code:
            private void btnMaterialsMouseClicked(java.awt.event.MouseEvent evt) {                                          
                cl.first(frmMaterials);
                cl.show(jPanel1, "1");
            }                                         
    
            private void btnCustomerMouseClicked(java.awt.event.MouseEvent evt) {                                         
                cl.first(frmCustomer);
                cl.show(jPanel1, "2");
            }
    But, there is an error in compile. Mostly the error is in the GENERATED CODE, I think I missing something or a lot. :)

    Please guide me.

    Thanks in Advance,
    geje
    Last edited by mine0926; 04-30-2010 at 04:28 AM.

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

    Default

    Look again at the CardLayout tutorial as you're using it all wrong. For one, you need to use a String as the second parameter when adding components to a container that uses card layout. Next of all, you are using the first method inappropriately and with the wrong parameter. Why are you calling it at all?

    Edit: you also seem to be trying to mix AWT (Frame) with Swing (JPanel) components, and this is something that in general shouldn't be done unless you have a very good reason to do so (you don't). Best of luck.
    Last edited by Fubarable; 04-30-2010 at 04:45 AM.

  6. #6
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Okay. I already figure it out. Thanks for pointing me to CardLayout.
    My first mistake is I change
    import javax.swing.JFrame.*; to import java.awt.Frame.*;
    that's why there are errors in generated code.

    Second:
    cl.first(frmMaterials); should be cl.first(jPanel1);

    It does not matter if I use JPanel or JInternalFrame for CardLayout. Both components are working great.

    Is there a way or is it possible to show both JPanel or InternalFrame?
    Because in CardLayout when I click button1 it shows form1 then when i click button2 it shows form2 and hides Form1
    Is there any way to still show Form1 while Form2 is Active but they are still MDI Child forms.
    *
    * Hope you understad what I am trying to say...


    Thank you very much,
    geje

  7. #7
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I was able to figure the awt.Frame.* and the cl.first(jPanel1).

    But I dont know what you mean by:
    Next of all, you are using the first method inappropriately and with the wrong parameter. Why are you calling it at all?
    Thanks,
    geje

  8. #8
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I was able to figure the awt.Frame.* and the cl.first(jPanel1).

    But I dont know what you mean by:
    Next of all, you are using the first method inappropriately and with the wrong parameter. Why are you calling it at all?
    I just follow the code on the link I said before. Also I cannot see CardLayout in Palette Form if that is what you mean
    Thanks,
    geje

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

  10. #10
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Thanks for guiding me, That is waht I wanted to do.
    How can I mark it [SOLVED]?
    geje

Similar Threads

  1. Use multiple forms
    By coco in forum Java Applets
    Replies: 2
    Last Post: 06-14-2010, 05:14 AM
  2. Switch between forms.
    By OMFGITSROHIT in forum AWT / Swing
    Replies: 9
    Last Post: 03-13-2010, 07:47 PM
  3. Forms in MultiPageEditorPart
    By darie20 in forum SWT / JFace
    Replies: 0
    Last Post: 02-01-2010, 12:22 PM
  4. Replies: 2
    Last Post: 04-28-2008, 10:56 AM
  5. Forms in jsp
    By bbq in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 04:28 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
  •