Page 2 of 4 FirstFirst 1234 LastLast
Results 21 to 40 of 77
  1. #21
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    -i want that when i will click the button(17-21 code line of New Form) that is on New Jpanel and
    initialy New JPanel is set on displaypanel that is in Main JFrame.
    after clicking button
    the Labelpanel will be added to the displaypanel.

  2. #22
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    Did you see this in post#20:
    The posted code has syntax errors and does not compile. How did you test this code if it doesn't compile?
    If you don't understand my response, don't ignore it, ask a question.

  3. #23
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    After fixing the syntax errors, I execute the code and I get a small window with two buttons: Label and New that are one above the other.
    What should I do next to see the problem? Your instructions don't say which button on the GUI to press.
    If you don't understand my response, don't ignore it, ask a question.

  4. #24
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    i am sending you the new tested and working codes.

    Main Form
    Java Code:
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    
    
    public class Main extends JFrame{
        JPanel displaypanel,buttonpanel,mainpanel;
        JButton label,new1;
        public Main()
        {
            setDefaultCloseOperation(Main.EXIT_ON_CLOSE);
            setBounds(0, 0, 500,500);
            displaypanel =new JPanel();
            buttonpanel =new JPanel();
            mainpanel =new JPanel(new BorderLayout());
            label = new JButton("Label");
            new1=new JButton("New");
            buttonpanel.add(label);
            buttonpanel.add(new1);
            mainpanel.add("West",buttonpanel);
            mainpanel.add("Center",displaypanel);
            getContentPane().add(mainpanel);
            label.addActionListener(new java.awt.event.ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                 JPanel p1=new Label();
                 display(p1);
                }        });
            new1.addActionListener(new java.awt.event.ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
           
                    JPanel p1=new New2();
                    display(p1);
                }
            });
        }
        public static void main(String args[])
        {
            new Main().setVisible(true);
        }
        public void display(JPanel panel)
        {
           displaypanel.removeAll();
           displaypanel.add(panel);
           displaypanel.updateUI();
        }
    }
    Last edited by sharmapiyush; 04-06-2014 at 08:48 PM.

  5. #25
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    Label Form

    Java Code:
    import javax.swing.*;
    public class Label extends JPanel{
        public Label()
        {
            JTextArea t1=new JTextArea(20, 20);
            add(t1);
            
        }
    }

  6. #26
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    New2 Form

    Java Code:
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    
    public class New2 extends JPanel{
        Main o=new Main();
        public New2()
        {
            JButton b1=new JButton("Label1");
            add(b1);
            b1.addActionListener(new java.awt.event.ActionListener() {
    
                @Override
                public void actionPerformed(ActionEvent e) {
                 JPanel p1=new Label();
                 o.display(p1);
                }
            });
        }
    }
    Last edited by sharmapiyush; 04-06-2014 at 08:51 PM.

  7. #27
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    now code line no 15 in new2 form is not working.
    line no 14-15 is use to switch from new2 form to label form when label1 button will be clicked

  8. #28
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    When I execute the code I can not see the line numbers. I see buttons and text fields.
    What buttons/labels are shown on the first screen?
    What action should I do with those?
    What should happen when I do that action?
    If you don't understand my response, don't ignore it, ask a question.

  9. #29
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    can you see the two buttons named label and new on the left side,that are in buttonpanel,and when you click on label button a new label panel has displayed right to it.on displaypanel.and when you click on new button a new panel has been added to the displaypanel and the old panel get removed from there,there is a button on that panel named label1,i want to do when i clicl on that button the label panel will be added to the displayepanel and the old panel will be removed.

    and i have told about the codes i have posted on website you can find the line numbers here easily.

  10. #30
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    1)see the two buttons named label and new Yes I see those.
    2) click on label button a new label panel has displayed right to it. >>> I get a text area where data can be entered.
    3)you click on new button a new panel has been added >> The text area is replaced with a button: Label1

    4)want to do when i clicl on that button the label panel will be added to the displayepanel and the old panel will be removed. >>> Nothing happens
    The code creates a new instance but does not set it visible.
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    yes i want to do that thing.
    how to do that...i have tried and trying.but nothing happens.

  12. #32
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    To make a JFrame visible, call its setVisible(true).
    If you don't understand my response, don't ignore it, ask a question.

  13. #33
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    but its not a jframe its a different panel class that have been called on jframe.
    see the codes again and tell me if you can do anything.

  14. #34
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    What is the "its" you are talking about?
    What happens when you call setVisible on the new instance of Main() created in the New class when its button listener method calls display()?
    If you don't understand my response, don't ignore it, ask a question.

  15. #35
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    its mean "label Jpanel".
    when i call display() method nothing happens.

  16. #36
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    The New class creates an instance of the Main class (variable name: o) but does NOT call the setVisible() method to make that instance visible. When it is visible you will see the results of the call to the display() method.
    Last edited by Norm; 04-07-2014 at 10:13 PM.
    If you don't understand my response, don't ignore it, ask a question.

  17. #37
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    yes i got that...but i dont want a new frame to visible...can it will be done on the same frame.is there any way to setvisible that(label jpanel) on the same frame on which it is clicked.

  18. #38
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: can't navigate from child panel to main panel

    can it will be done on the same frame
    Yes, pass a reference to that class's instance to where you want to call its methods.
    If you don't understand my response, don't ignore it, ask a question.

  19. #39
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    can you please tell me how to do that.which reference i have to pass to class'instance.

  20. #40
    sharmapiyush is offline Member
    Join Date
    Apr 2014
    Posts
    74
    Rep Power
    0

    Default Re: can't navigate from child panel to main panel

    i have already pass "p1" to the class instance but it did not work ."

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 04-03-2011, 12:35 PM
  2. panel on a panel not visible
    By warchieflll in forum Advanced Java
    Replies: 2
    Last Post: 01-29-2011, 08:29 PM
  3. Displaying panels inside a main panel
    By Sneaky Fox in forum AWT / Swing
    Replies: 4
    Last Post: 01-21-2011, 04:12 PM
  4. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 08:43 PM
  5. How to add more components to main panel
    By aneesahamedaa in forum AWT / Swing
    Replies: 4
    Last Post: 08-21-2008, 06:31 PM

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
  •