How to implement pages in Java Swing app.?












0















I have some experience in Java creating Apps and would like to learn more, and so have decided to create an application that will have different pages. For example the initial frame will show a menu of buttons that will lead to different frames, showing different components and layouts.



I'm not too sure the best practice of implementing pages. I think I could store the JFrame windows in a list, then use a button handler class to maybe change the visibility of the different frames, only allowing the relevant frame to be visible when the user clicks on a button. I think this method could work, but is there a more efficient/practical way of doing this?



I am aware of CardLayout, however for this program I am trying to learn MigLayout; so that won't be possible (as far as I'm aware). I hope this question is not too vague, I'd just like to know the best practice when it comes to creating applications in Java with different pages.










share|improve this question




















  • 3





    1) Yes you can use CardLayout. The panel with the CardLayout is the "parent" panel. Then you have child panels you add to the CardLayout. These panels can use whatever layout manger they want. 2) Don't use multiple frames. If you need separate windows then you should be using a JDialog as a child window.

    – camickr
    Nov 23 '18 at 22:04











  • There's any number of ways you "might" do this. CardLayout is certainly an option, but doesn't always fit every situation (nothing ever does). Sometimes you need to "roll your own" solution, which might use a model and controller to manage a collection of views. This would be some what more dynamic in nature, but would require more work on you end to make it work

    – MadProgrammer
    Nov 23 '18 at 23:11
















0















I have some experience in Java creating Apps and would like to learn more, and so have decided to create an application that will have different pages. For example the initial frame will show a menu of buttons that will lead to different frames, showing different components and layouts.



I'm not too sure the best practice of implementing pages. I think I could store the JFrame windows in a list, then use a button handler class to maybe change the visibility of the different frames, only allowing the relevant frame to be visible when the user clicks on a button. I think this method could work, but is there a more efficient/practical way of doing this?



I am aware of CardLayout, however for this program I am trying to learn MigLayout; so that won't be possible (as far as I'm aware). I hope this question is not too vague, I'd just like to know the best practice when it comes to creating applications in Java with different pages.










share|improve this question




















  • 3





    1) Yes you can use CardLayout. The panel with the CardLayout is the "parent" panel. Then you have child panels you add to the CardLayout. These panels can use whatever layout manger they want. 2) Don't use multiple frames. If you need separate windows then you should be using a JDialog as a child window.

    – camickr
    Nov 23 '18 at 22:04











  • There's any number of ways you "might" do this. CardLayout is certainly an option, but doesn't always fit every situation (nothing ever does). Sometimes you need to "roll your own" solution, which might use a model and controller to manage a collection of views. This would be some what more dynamic in nature, but would require more work on you end to make it work

    – MadProgrammer
    Nov 23 '18 at 23:11














0












0








0








I have some experience in Java creating Apps and would like to learn more, and so have decided to create an application that will have different pages. For example the initial frame will show a menu of buttons that will lead to different frames, showing different components and layouts.



I'm not too sure the best practice of implementing pages. I think I could store the JFrame windows in a list, then use a button handler class to maybe change the visibility of the different frames, only allowing the relevant frame to be visible when the user clicks on a button. I think this method could work, but is there a more efficient/practical way of doing this?



I am aware of CardLayout, however for this program I am trying to learn MigLayout; so that won't be possible (as far as I'm aware). I hope this question is not too vague, I'd just like to know the best practice when it comes to creating applications in Java with different pages.










share|improve this question
















I have some experience in Java creating Apps and would like to learn more, and so have decided to create an application that will have different pages. For example the initial frame will show a menu of buttons that will lead to different frames, showing different components and layouts.



I'm not too sure the best practice of implementing pages. I think I could store the JFrame windows in a list, then use a button handler class to maybe change the visibility of the different frames, only allowing the relevant frame to be visible when the user clicks on a button. I think this method could work, but is there a more efficient/practical way of doing this?



I am aware of CardLayout, however for this program I am trying to learn MigLayout; so that won't be possible (as far as I'm aware). I hope this question is not too vague, I'd just like to know the best practice when it comes to creating applications in Java with different pages.







java swing user-interface layout-manager






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 3:54









Andrew Thompson

153k28162343




153k28162343










asked Nov 23 '18 at 21:50









Sean2148Sean2148

10318




10318








  • 3





    1) Yes you can use CardLayout. The panel with the CardLayout is the "parent" panel. Then you have child panels you add to the CardLayout. These panels can use whatever layout manger they want. 2) Don't use multiple frames. If you need separate windows then you should be using a JDialog as a child window.

    – camickr
    Nov 23 '18 at 22:04











  • There's any number of ways you "might" do this. CardLayout is certainly an option, but doesn't always fit every situation (nothing ever does). Sometimes you need to "roll your own" solution, which might use a model and controller to manage a collection of views. This would be some what more dynamic in nature, but would require more work on you end to make it work

    – MadProgrammer
    Nov 23 '18 at 23:11














  • 3





    1) Yes you can use CardLayout. The panel with the CardLayout is the "parent" panel. Then you have child panels you add to the CardLayout. These panels can use whatever layout manger they want. 2) Don't use multiple frames. If you need separate windows then you should be using a JDialog as a child window.

    – camickr
    Nov 23 '18 at 22:04











  • There's any number of ways you "might" do this. CardLayout is certainly an option, but doesn't always fit every situation (nothing ever does). Sometimes you need to "roll your own" solution, which might use a model and controller to manage a collection of views. This would be some what more dynamic in nature, but would require more work on you end to make it work

    – MadProgrammer
    Nov 23 '18 at 23:11








3




3





1) Yes you can use CardLayout. The panel with the CardLayout is the "parent" panel. Then you have child panels you add to the CardLayout. These panels can use whatever layout manger they want. 2) Don't use multiple frames. If you need separate windows then you should be using a JDialog as a child window.

– camickr
Nov 23 '18 at 22:04





1) Yes you can use CardLayout. The panel with the CardLayout is the "parent" panel. Then you have child panels you add to the CardLayout. These panels can use whatever layout manger they want. 2) Don't use multiple frames. If you need separate windows then you should be using a JDialog as a child window.

– camickr
Nov 23 '18 at 22:04













There's any number of ways you "might" do this. CardLayout is certainly an option, but doesn't always fit every situation (nothing ever does). Sometimes you need to "roll your own" solution, which might use a model and controller to manage a collection of views. This would be some what more dynamic in nature, but would require more work on you end to make it work

– MadProgrammer
Nov 23 '18 at 23:11





There's any number of ways you "might" do this. CardLayout is certainly an option, but doesn't always fit every situation (nothing ever does). Sometimes you need to "roll your own" solution, which might use a model and controller to manage a collection of views. This would be some what more dynamic in nature, but would require more work on you end to make it work

– MadProgrammer
Nov 23 '18 at 23:11












2 Answers
2






active

oldest

votes


















0














Can use Tabbed Panes, it is the best for storing pages.



https://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html



Also I noticed that you need to consider top level containers properly, because you don't need to create every time a JFrame for each Page, at least if it was necessary(For example: an editor, create a new window so you need to create a new JFrame, in your case I don't think so) so please consider the link below.



https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html






share|improve this answer































    0














    JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc. Internal frames with components example



    Code to create multiple internal frames:



    import java.awt.event.*; 
    import java.awt.*;
    import javax.swing.*;

    class solution extends JFrame {

    // frame
    static JFrame f;

    // label to diaplay text
    static JLabel l, l1;

    // main class
    public static void main(String args) {
    // create a new frame
    f = new JFrame("frame");

    // set layout of frame
    f.setLayout(new FlowLayout());

    // create a internal frame
    JInternalFrame in = new JInternalFrame("frame 1", true, true, true, true);

    // create a internal frame
    JInternalFrame in1 = new JInternalFrame("frame 2", true, true, true, true);

    // create a Button
    JButton b = new JButton("button");
    JButton b1 = new JButton("button1");

    // create a label to display text
    l = new JLabel("This is a JInternal Frame no 1 ");
    l1 = new JLabel("This is a JInternal Frame no 2 ");

    // create a panel
    JPanel p = new JPanel();
    JPanel p1 = new JPanel();

    // add label and button to panel
    p.add(l);
    p.add(b);
    p1.add(l1);
    p1.add(b1);

    // set visibility internal frame
    in.setVisible(true);
    in1.setVisible(true);

    // add panel to internal frame
    in.add(p);
    in1.add(p1);

    // add internal frame to frame
    f.add(in);
    f.add(in1);

    // set the size of frame
    f.setSize(300, 300);

    f.show();
    }
    }





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453284%2fhow-to-implement-pages-in-java-swing-app%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Can use Tabbed Panes, it is the best for storing pages.



      https://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html



      Also I noticed that you need to consider top level containers properly, because you don't need to create every time a JFrame for each Page, at least if it was necessary(For example: an editor, create a new window so you need to create a new JFrame, in your case I don't think so) so please consider the link below.



      https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html






      share|improve this answer




























        0














        Can use Tabbed Panes, it is the best for storing pages.



        https://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html



        Also I noticed that you need to consider top level containers properly, because you don't need to create every time a JFrame for each Page, at least if it was necessary(For example: an editor, create a new window so you need to create a new JFrame, in your case I don't think so) so please consider the link below.



        https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html






        share|improve this answer


























          0












          0








          0







          Can use Tabbed Panes, it is the best for storing pages.



          https://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html



          Also I noticed that you need to consider top level containers properly, because you don't need to create every time a JFrame for each Page, at least if it was necessary(For example: an editor, create a new window so you need to create a new JFrame, in your case I don't think so) so please consider the link below.



          https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html






          share|improve this answer













          Can use Tabbed Panes, it is the best for storing pages.



          https://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html



          Also I noticed that you need to consider top level containers properly, because you don't need to create every time a JFrame for each Page, at least if it was necessary(For example: an editor, create a new window so you need to create a new JFrame, in your case I don't think so) so please consider the link below.



          https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 23:47









          Jonathan JohxJonathan Johx

          1,7761317




          1,7761317

























              0














              JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc. Internal frames with components example



              Code to create multiple internal frames:



              import java.awt.event.*; 
              import java.awt.*;
              import javax.swing.*;

              class solution extends JFrame {

              // frame
              static JFrame f;

              // label to diaplay text
              static JLabel l, l1;

              // main class
              public static void main(String args) {
              // create a new frame
              f = new JFrame("frame");

              // set layout of frame
              f.setLayout(new FlowLayout());

              // create a internal frame
              JInternalFrame in = new JInternalFrame("frame 1", true, true, true, true);

              // create a internal frame
              JInternalFrame in1 = new JInternalFrame("frame 2", true, true, true, true);

              // create a Button
              JButton b = new JButton("button");
              JButton b1 = new JButton("button1");

              // create a label to display text
              l = new JLabel("This is a JInternal Frame no 1 ");
              l1 = new JLabel("This is a JInternal Frame no 2 ");

              // create a panel
              JPanel p = new JPanel();
              JPanel p1 = new JPanel();

              // add label and button to panel
              p.add(l);
              p.add(b);
              p1.add(l1);
              p1.add(b1);

              // set visibility internal frame
              in.setVisible(true);
              in1.setVisible(true);

              // add panel to internal frame
              in.add(p);
              in1.add(p1);

              // add internal frame to frame
              f.add(in);
              f.add(in1);

              // set the size of frame
              f.setSize(300, 300);

              f.show();
              }
              }





              share|improve this answer




























                0














                JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc. Internal frames with components example



                Code to create multiple internal frames:



                import java.awt.event.*; 
                import java.awt.*;
                import javax.swing.*;

                class solution extends JFrame {

                // frame
                static JFrame f;

                // label to diaplay text
                static JLabel l, l1;

                // main class
                public static void main(String args) {
                // create a new frame
                f = new JFrame("frame");

                // set layout of frame
                f.setLayout(new FlowLayout());

                // create a internal frame
                JInternalFrame in = new JInternalFrame("frame 1", true, true, true, true);

                // create a internal frame
                JInternalFrame in1 = new JInternalFrame("frame 2", true, true, true, true);

                // create a Button
                JButton b = new JButton("button");
                JButton b1 = new JButton("button1");

                // create a label to display text
                l = new JLabel("This is a JInternal Frame no 1 ");
                l1 = new JLabel("This is a JInternal Frame no 2 ");

                // create a panel
                JPanel p = new JPanel();
                JPanel p1 = new JPanel();

                // add label and button to panel
                p.add(l);
                p.add(b);
                p1.add(l1);
                p1.add(b1);

                // set visibility internal frame
                in.setVisible(true);
                in1.setVisible(true);

                // add panel to internal frame
                in.add(p);
                in1.add(p1);

                // add internal frame to frame
                f.add(in);
                f.add(in1);

                // set the size of frame
                f.setSize(300, 300);

                f.show();
                }
                }





                share|improve this answer


























                  0












                  0








                  0







                  JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc. Internal frames with components example



                  Code to create multiple internal frames:



                  import java.awt.event.*; 
                  import java.awt.*;
                  import javax.swing.*;

                  class solution extends JFrame {

                  // frame
                  static JFrame f;

                  // label to diaplay text
                  static JLabel l, l1;

                  // main class
                  public static void main(String args) {
                  // create a new frame
                  f = new JFrame("frame");

                  // set layout of frame
                  f.setLayout(new FlowLayout());

                  // create a internal frame
                  JInternalFrame in = new JInternalFrame("frame 1", true, true, true, true);

                  // create a internal frame
                  JInternalFrame in1 = new JInternalFrame("frame 2", true, true, true, true);

                  // create a Button
                  JButton b = new JButton("button");
                  JButton b1 = new JButton("button1");

                  // create a label to display text
                  l = new JLabel("This is a JInternal Frame no 1 ");
                  l1 = new JLabel("This is a JInternal Frame no 2 ");

                  // create a panel
                  JPanel p = new JPanel();
                  JPanel p1 = new JPanel();

                  // add label and button to panel
                  p.add(l);
                  p.add(b);
                  p1.add(l1);
                  p1.add(b1);

                  // set visibility internal frame
                  in.setVisible(true);
                  in1.setVisible(true);

                  // add panel to internal frame
                  in.add(p);
                  in1.add(p1);

                  // add internal frame to frame
                  f.add(in);
                  f.add(in1);

                  // set the size of frame
                  f.setSize(300, 300);

                  f.show();
                  }
                  }





                  share|improve this answer













                  JInternalFrame is a part of Java Swing . JInternalFrame is a container that provides many features of a frame which includes displaying title, opening, closing, resizing, support for menu bar, etc. Internal frames with components example



                  Code to create multiple internal frames:



                  import java.awt.event.*; 
                  import java.awt.*;
                  import javax.swing.*;

                  class solution extends JFrame {

                  // frame
                  static JFrame f;

                  // label to diaplay text
                  static JLabel l, l1;

                  // main class
                  public static void main(String args) {
                  // create a new frame
                  f = new JFrame("frame");

                  // set layout of frame
                  f.setLayout(new FlowLayout());

                  // create a internal frame
                  JInternalFrame in = new JInternalFrame("frame 1", true, true, true, true);

                  // create a internal frame
                  JInternalFrame in1 = new JInternalFrame("frame 2", true, true, true, true);

                  // create a Button
                  JButton b = new JButton("button");
                  JButton b1 = new JButton("button1");

                  // create a label to display text
                  l = new JLabel("This is a JInternal Frame no 1 ");
                  l1 = new JLabel("This is a JInternal Frame no 2 ");

                  // create a panel
                  JPanel p = new JPanel();
                  JPanel p1 = new JPanel();

                  // add label and button to panel
                  p.add(l);
                  p.add(b);
                  p1.add(l1);
                  p1.add(b1);

                  // set visibility internal frame
                  in.setVisible(true);
                  in1.setVisible(true);

                  // add panel to internal frame
                  in.add(p);
                  in1.add(p1);

                  // add internal frame to frame
                  f.add(in);
                  f.add(in1);

                  // set the size of frame
                  f.setSize(300, 300);

                  f.show();
                  }
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 28 '18 at 13:13









                  Tomka KoliadaTomka Koliada

                  7611427




                  7611427






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453284%2fhow-to-implement-pages-in-java-swing-app%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen