Codename One app shown in a centered rectangle on wide screens












1















Note for the readers: this question is referred exclusively to Codename One.



Because I have multiple targets for the same app (Android, iOS, Javascript), that can be run on small screens (that is the typical use case) but also on wide screens, I have to do a choice about the UI.



I want to simplify my life: mobile devices held on portrait mode are my primary target, so... all wide screens (desktop and tablet) will show the app inside a vertical rectangle in the center of the screen. Maybe this is not the best solution, but it can make sense. I suppose that the width of that centered rectangle is 9 cm (my iPhone device width is about 7 cm and my Android device width is about 8 cm).



So... what is a proper way to accomplish this requirement?



Initially I thought that I can create a BaseForm with a code that override the show() method, setting a left and right margin for ContentPane, LayeredPane and Toolbar before calling super.show()... but this solution seems to me a poor way to go and also an overhead, because in that case I'll need to recalculate the margins and to revalidate the BaseForm for every change of size of screen... and, however, this solution will not work with FABs or Dialogs. So... it's not a solution.



It could be nice if I can choose a background (an image or a color) for all the space outside the centered rectangle containing the app.



Any better idea?










share|improve this question



























    1















    Note for the readers: this question is referred exclusively to Codename One.



    Because I have multiple targets for the same app (Android, iOS, Javascript), that can be run on small screens (that is the typical use case) but also on wide screens, I have to do a choice about the UI.



    I want to simplify my life: mobile devices held on portrait mode are my primary target, so... all wide screens (desktop and tablet) will show the app inside a vertical rectangle in the center of the screen. Maybe this is not the best solution, but it can make sense. I suppose that the width of that centered rectangle is 9 cm (my iPhone device width is about 7 cm and my Android device width is about 8 cm).



    So... what is a proper way to accomplish this requirement?



    Initially I thought that I can create a BaseForm with a code that override the show() method, setting a left and right margin for ContentPane, LayeredPane and Toolbar before calling super.show()... but this solution seems to me a poor way to go and also an overhead, because in that case I'll need to recalculate the margins and to revalidate the BaseForm for every change of size of screen... and, however, this solution will not work with FABs or Dialogs. So... it's not a solution.



    It could be nice if I can choose a background (an image or a color) for all the space outside the centered rectangle containing the app.



    Any better idea?










    share|improve this question

























      1












      1








      1


      1






      Note for the readers: this question is referred exclusively to Codename One.



      Because I have multiple targets for the same app (Android, iOS, Javascript), that can be run on small screens (that is the typical use case) but also on wide screens, I have to do a choice about the UI.



      I want to simplify my life: mobile devices held on portrait mode are my primary target, so... all wide screens (desktop and tablet) will show the app inside a vertical rectangle in the center of the screen. Maybe this is not the best solution, but it can make sense. I suppose that the width of that centered rectangle is 9 cm (my iPhone device width is about 7 cm and my Android device width is about 8 cm).



      So... what is a proper way to accomplish this requirement?



      Initially I thought that I can create a BaseForm with a code that override the show() method, setting a left and right margin for ContentPane, LayeredPane and Toolbar before calling super.show()... but this solution seems to me a poor way to go and also an overhead, because in that case I'll need to recalculate the margins and to revalidate the BaseForm for every change of size of screen... and, however, this solution will not work with FABs or Dialogs. So... it's not a solution.



      It could be nice if I can choose a background (an image or a color) for all the space outside the centered rectangle containing the app.



      Any better idea?










      share|improve this question














      Note for the readers: this question is referred exclusively to Codename One.



      Because I have multiple targets for the same app (Android, iOS, Javascript), that can be run on small screens (that is the typical use case) but also on wide screens, I have to do a choice about the UI.



      I want to simplify my life: mobile devices held on portrait mode are my primary target, so... all wide screens (desktop and tablet) will show the app inside a vertical rectangle in the center of the screen. Maybe this is not the best solution, but it can make sense. I suppose that the width of that centered rectangle is 9 cm (my iPhone device width is about 7 cm and my Android device width is about 8 cm).



      So... what is a proper way to accomplish this requirement?



      Initially I thought that I can create a BaseForm with a code that override the show() method, setting a left and right margin for ContentPane, LayeredPane and Toolbar before calling super.show()... but this solution seems to me a poor way to go and also an overhead, because in that case I'll need to recalculate the margins and to revalidate the BaseForm for every change of size of screen... and, however, this solution will not work with FABs or Dialogs. So... it's not a solution.



      It could be nice if I can choose a background (an image or a color) for all the space outside the centered rectangle containing the app.



      Any better idea?







      codenameone






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 21:16









      Francesco GalganiFrancesco Galgani

      1,386613




      1,386613
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This is probably something that we need to implement in the system to make it seamless. Any approach you choose will require some work.



          If I were doing something like this I'd create a special form with no title that acts as your background. I'd give it a special custom layout manager that centers the content. Something like:



          public CenterOneCompnentLayout class Layout {
          public void layoutContainer(Container parent) {
          if(parent.getComponentCount() == 1) {
          Component cmp = parent.getComponentAt(0);
          cmp.setWidth(convertToPixels(9));
          cmp.setHeight(parent.getHeight());
          cmp.setY(0);
          cmp.setX(parent.getWidth() / 2 - cmp.getWidth() / 2);
          }
          }

          public Dimension getPreferredSize(Container parent) {
          return new Dimension(100, 100);
          }
          }


          Now just add the actual form to this background form. The rest should work "as is". I think you would need to guard against some things and it's possible this hack will produce some side effects due to the nesting of the forms. But ultimately it should work.






          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%2f53489186%2fcodename-one-app-shown-in-a-centered-rectangle-on-wide-screens%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            This is probably something that we need to implement in the system to make it seamless. Any approach you choose will require some work.



            If I were doing something like this I'd create a special form with no title that acts as your background. I'd give it a special custom layout manager that centers the content. Something like:



            public CenterOneCompnentLayout class Layout {
            public void layoutContainer(Container parent) {
            if(parent.getComponentCount() == 1) {
            Component cmp = parent.getComponentAt(0);
            cmp.setWidth(convertToPixels(9));
            cmp.setHeight(parent.getHeight());
            cmp.setY(0);
            cmp.setX(parent.getWidth() / 2 - cmp.getWidth() / 2);
            }
            }

            public Dimension getPreferredSize(Container parent) {
            return new Dimension(100, 100);
            }
            }


            Now just add the actual form to this background form. The rest should work "as is". I think you would need to guard against some things and it's possible this hack will produce some side effects due to the nesting of the forms. But ultimately it should work.






            share|improve this answer




























              1














              This is probably something that we need to implement in the system to make it seamless. Any approach you choose will require some work.



              If I were doing something like this I'd create a special form with no title that acts as your background. I'd give it a special custom layout manager that centers the content. Something like:



              public CenterOneCompnentLayout class Layout {
              public void layoutContainer(Container parent) {
              if(parent.getComponentCount() == 1) {
              Component cmp = parent.getComponentAt(0);
              cmp.setWidth(convertToPixels(9));
              cmp.setHeight(parent.getHeight());
              cmp.setY(0);
              cmp.setX(parent.getWidth() / 2 - cmp.getWidth() / 2);
              }
              }

              public Dimension getPreferredSize(Container parent) {
              return new Dimension(100, 100);
              }
              }


              Now just add the actual form to this background form. The rest should work "as is". I think you would need to guard against some things and it's possible this hack will produce some side effects due to the nesting of the forms. But ultimately it should work.






              share|improve this answer


























                1












                1








                1







                This is probably something that we need to implement in the system to make it seamless. Any approach you choose will require some work.



                If I were doing something like this I'd create a special form with no title that acts as your background. I'd give it a special custom layout manager that centers the content. Something like:



                public CenterOneCompnentLayout class Layout {
                public void layoutContainer(Container parent) {
                if(parent.getComponentCount() == 1) {
                Component cmp = parent.getComponentAt(0);
                cmp.setWidth(convertToPixels(9));
                cmp.setHeight(parent.getHeight());
                cmp.setY(0);
                cmp.setX(parent.getWidth() / 2 - cmp.getWidth() / 2);
                }
                }

                public Dimension getPreferredSize(Container parent) {
                return new Dimension(100, 100);
                }
                }


                Now just add the actual form to this background form. The rest should work "as is". I think you would need to guard against some things and it's possible this hack will produce some side effects due to the nesting of the forms. But ultimately it should work.






                share|improve this answer













                This is probably something that we need to implement in the system to make it seamless. Any approach you choose will require some work.



                If I were doing something like this I'd create a special form with no title that acts as your background. I'd give it a special custom layout manager that centers the content. Something like:



                public CenterOneCompnentLayout class Layout {
                public void layoutContainer(Container parent) {
                if(parent.getComponentCount() == 1) {
                Component cmp = parent.getComponentAt(0);
                cmp.setWidth(convertToPixels(9));
                cmp.setHeight(parent.getHeight());
                cmp.setY(0);
                cmp.setX(parent.getWidth() / 2 - cmp.getWidth() / 2);
                }
                }

                public Dimension getPreferredSize(Container parent) {
                return new Dimension(100, 100);
                }
                }


                Now just add the actual form to this background form. The rest should work "as is". I think you would need to guard against some things and it's possible this hack will produce some side effects due to the nesting of the forms. But ultimately it should work.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '18 at 4:24









                Shai AlmogShai Almog

                40.7k52555




                40.7k52555
































                    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%2f53489186%2fcodename-one-app-shown-in-a-centered-rectangle-on-wide-screens%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

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)