Complex layout of multiple components












0















I am designing a GUI where I have the components shown below. But in the second row, I would like to manage spaces between the components. For example, in the second row, I would like to fit both the JLabel "Move to time" and the JTextField without so much spacing. As I can see, right now MigLayout places the JTextField in line with the second component in the first row. Then, the JButton "Move" in the 2nd row should be aligned to the 2nd component in the first row. How do I achieve this? Below is my code. I looked up many cheat sheets and quick start guides on MigLayout but I couldn't manage yet. Can somebody recommend changes in my code snippet? Thank you.



`



    JPanel helper = new JPanel( new MigLayout( "" ) );
helper.add( new JButton( "Add puncta coordinates from CSV" ), "width 250:20" );
helper.add( new JButton( "Add track coordinates from CSV" ), "wrap" );
helper.add( new JLabel( "Move to time:" ) );
JTextField tMoveTime = new JTextField();
helper.add( tMoveTime, " gap 2px, width 75:20" );
JButton bMoveTime = initMoveButton();
helper.add( bMoveTime, "width 75:20" );


`



enter image description here



Actually, I intend to make the following GUI in full with all buttons and textfields, is any other layout more suited? If yes, can an example code snippet for the recommended layout be pointed to? Thank you.



enter image description here










share|improve this question

























  • Does it have to be MigLayout ?

    – c0der
    Jan 2 at 5:58











  • @c0der No, it doesn't have to be, but in fact I started with MigLayout. Actually, I am trying to make the full GUI with all the buttons and fields (question updated and full GUI picture posted). I started with MigLayout, what can you recommend? Also can you please post some helpful code snippet for the recommended Layout? Thanks

    – Silver moon
    Jan 2 at 8:48


















0















I am designing a GUI where I have the components shown below. But in the second row, I would like to manage spaces between the components. For example, in the second row, I would like to fit both the JLabel "Move to time" and the JTextField without so much spacing. As I can see, right now MigLayout places the JTextField in line with the second component in the first row. Then, the JButton "Move" in the 2nd row should be aligned to the 2nd component in the first row. How do I achieve this? Below is my code. I looked up many cheat sheets and quick start guides on MigLayout but I couldn't manage yet. Can somebody recommend changes in my code snippet? Thank you.



`



    JPanel helper = new JPanel( new MigLayout( "" ) );
helper.add( new JButton( "Add puncta coordinates from CSV" ), "width 250:20" );
helper.add( new JButton( "Add track coordinates from CSV" ), "wrap" );
helper.add( new JLabel( "Move to time:" ) );
JTextField tMoveTime = new JTextField();
helper.add( tMoveTime, " gap 2px, width 75:20" );
JButton bMoveTime = initMoveButton();
helper.add( bMoveTime, "width 75:20" );


`



enter image description here



Actually, I intend to make the following GUI in full with all buttons and textfields, is any other layout more suited? If yes, can an example code snippet for the recommended layout be pointed to? Thank you.



enter image description here










share|improve this question

























  • Does it have to be MigLayout ?

    – c0der
    Jan 2 at 5:58











  • @c0der No, it doesn't have to be, but in fact I started with MigLayout. Actually, I am trying to make the full GUI with all the buttons and fields (question updated and full GUI picture posted). I started with MigLayout, what can you recommend? Also can you please post some helpful code snippet for the recommended Layout? Thanks

    – Silver moon
    Jan 2 at 8:48
















0












0








0








I am designing a GUI where I have the components shown below. But in the second row, I would like to manage spaces between the components. For example, in the second row, I would like to fit both the JLabel "Move to time" and the JTextField without so much spacing. As I can see, right now MigLayout places the JTextField in line with the second component in the first row. Then, the JButton "Move" in the 2nd row should be aligned to the 2nd component in the first row. How do I achieve this? Below is my code. I looked up many cheat sheets and quick start guides on MigLayout but I couldn't manage yet. Can somebody recommend changes in my code snippet? Thank you.



`



    JPanel helper = new JPanel( new MigLayout( "" ) );
helper.add( new JButton( "Add puncta coordinates from CSV" ), "width 250:20" );
helper.add( new JButton( "Add track coordinates from CSV" ), "wrap" );
helper.add( new JLabel( "Move to time:" ) );
JTextField tMoveTime = new JTextField();
helper.add( tMoveTime, " gap 2px, width 75:20" );
JButton bMoveTime = initMoveButton();
helper.add( bMoveTime, "width 75:20" );


`



enter image description here



Actually, I intend to make the following GUI in full with all buttons and textfields, is any other layout more suited? If yes, can an example code snippet for the recommended layout be pointed to? Thank you.



enter image description here










share|improve this question
















I am designing a GUI where I have the components shown below. But in the second row, I would like to manage spaces between the components. For example, in the second row, I would like to fit both the JLabel "Move to time" and the JTextField without so much spacing. As I can see, right now MigLayout places the JTextField in line with the second component in the first row. Then, the JButton "Move" in the 2nd row should be aligned to the 2nd component in the first row. How do I achieve this? Below is my code. I looked up many cheat sheets and quick start guides on MigLayout but I couldn't manage yet. Can somebody recommend changes in my code snippet? Thank you.



`



    JPanel helper = new JPanel( new MigLayout( "" ) );
helper.add( new JButton( "Add puncta coordinates from CSV" ), "width 250:20" );
helper.add( new JButton( "Add track coordinates from CSV" ), "wrap" );
helper.add( new JLabel( "Move to time:" ) );
JTextField tMoveTime = new JTextField();
helper.add( tMoveTime, " gap 2px, width 75:20" );
JButton bMoveTime = initMoveButton();
helper.add( bMoveTime, "width 75:20" );


`



enter image description here



Actually, I intend to make the following GUI in full with all buttons and textfields, is any other layout more suited? If yes, can an example code snippet for the recommended layout be pointed to? Thank you.



enter image description here







java swing user-interface layout-manager miglayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 17:42









c0der

9,21651846




9,21651846










asked Jan 1 at 17:15









Silver moonSilver moon

1328




1328













  • Does it have to be MigLayout ?

    – c0der
    Jan 2 at 5:58











  • @c0der No, it doesn't have to be, but in fact I started with MigLayout. Actually, I am trying to make the full GUI with all the buttons and fields (question updated and full GUI picture posted). I started with MigLayout, what can you recommend? Also can you please post some helpful code snippet for the recommended Layout? Thanks

    – Silver moon
    Jan 2 at 8:48





















  • Does it have to be MigLayout ?

    – c0der
    Jan 2 at 5:58











  • @c0der No, it doesn't have to be, but in fact I started with MigLayout. Actually, I am trying to make the full GUI with all the buttons and fields (question updated and full GUI picture posted). I started with MigLayout, what can you recommend? Also can you please post some helpful code snippet for the recommended Layout? Thanks

    – Silver moon
    Jan 2 at 8:48



















Does it have to be MigLayout ?

– c0der
Jan 2 at 5:58





Does it have to be MigLayout ?

– c0der
Jan 2 at 5:58













@c0der No, it doesn't have to be, but in fact I started with MigLayout. Actually, I am trying to make the full GUI with all the buttons and fields (question updated and full GUI picture posted). I started with MigLayout, what can you recommend? Also can you please post some helpful code snippet for the recommended Layout? Thanks

– Silver moon
Jan 2 at 8:48







@c0der No, it doesn't have to be, but in fact I started with MigLayout. Actually, I am trying to make the full GUI with all the buttons and fields (question updated and full GUI picture posted). I started with MigLayout, what can you recommend? Also can you please post some helpful code snippet for the recommended Layout? Thanks

– Silver moon
Jan 2 at 8:48














1 Answer
1






active

oldest

votes


















1














You can consider two basic approaches :
One is to use highly flexible layout manager, like MigLayout. I am not familiar with it, but I can recommend GridbagLayout for the job:



    JPanel helper = new JPanel(  );
GridBagLayout gbl_helper = new GridBagLayout();
gbl_helper.columnWidths = new int{200, 7, 200, 60, 18, 0};
gbl_helper.rowHeights = new int{20, 20};
gbl_helper.columnWeights = new double{1.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
gbl_helper.rowWeights = new double{0.0, 0};
helper.setLayout(gbl_helper);

GridBagConstraints gbc1 = new GridBagConstraints();
gbc1.fill = GridBagConstraints.HORIZONTAL;
gbc1.gridwidth = 2;
gbc1.anchor = GridBagConstraints.NORTHWEST;
gbc1.insets = new Insets(5,5,5,5);
gbc1.gridx = 0;
gbc1.gridy = 0;
JButton button1 = new JButton( "Add puncta coordinates from CSV" );
helper.add( button1, gbc1 );

GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.fill = GridBagConstraints.HORIZONTAL;
gbc2.gridwidth = 2;
gbc2.anchor = GridBagConstraints.NORTHWEST;
gbc2.insets = new Insets(5,5,5,5);
gbc2.gridx = 2;
gbc2.gridy = 0;
JButton button2 = new JButton( "Add track coordinates from CSV" );

helper.add( button2, gbc2 );

GridBagConstraints gbc3 = new GridBagConstraints();
gbc3.insets = new Insets(0, 0, 0, 5);
gbc3.gridx = 0;
gbc3.gridy = 1;
JLabel label = new JLabel( "Move to time:" );
helper.add( label, gbc3 );

JTextField tMoveTime = new JTextField();
tMoveTime.setColumns(15);
GridBagConstraints gbc4 = new GridBagConstraints();
gbc4.anchor = GridBagConstraints.WEST;
gbc4.insets = new Insets(0, 0, 0, 5);
gbc4.gridx = 1;
gbc4.gridy = 1;
helper.add( tMoveTime, gbc4);

JButton bMoveTime = new JButton("Move");
GridBagConstraints gbc5 = new GridBagConstraints();
gbc5.insets = new Insets(0, 0, 0, 5);
gbc5.anchor = GridBagConstraints.NORTHEAST;
gbc5.gridx = 3;
gbc5.gridy = 1;
helper.add( bMoveTime, gbc5 );


enter image description here



A different approach is to divide a complex layout to simpler layouts by using sub - panels, each with it's own layout manager:



enter image description here



    JPanel helper = new JPanel(  );
helper.setLayout(new BoxLayout(helper, BoxLayout.Y_AXIS));
getContentPane().add(helper);

JPanel topPanel = new JPanel();
helper.add(topPanel);
JButton button1 = new JButton( "Add puncta coordinates from CSV" );
topPanel.add(button1);
JButton button2 = new JButton( "Add track coordinates from CSV" );
topPanel.add(button2);

JPanel bottomPanel = new JPanel();
helper.add(bottomPanel);
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

JPanel bottomRIght = new JPanel();
bottomPanel.add(bottomRIght);
JLabel label = new JLabel( "Move to time:" );
bottomRIght.add(label);
JTextField tMoveTime = new JTextField();
bottomRIght.add(tMoveTime);
tMoveTime.setColumns(15);

JPanel bottomleftPanel = new JPanel();
bottomPanel.add(bottomleftPanel);
bottomleftPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
JButton bMoveTime = new JButton("Move");
bottomleftPanel.add(bMoveTime);


enter image description here






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%2f53997402%2fcomplex-layout-of-multiple-components%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














    You can consider two basic approaches :
    One is to use highly flexible layout manager, like MigLayout. I am not familiar with it, but I can recommend GridbagLayout for the job:



        JPanel helper = new JPanel(  );
    GridBagLayout gbl_helper = new GridBagLayout();
    gbl_helper.columnWidths = new int{200, 7, 200, 60, 18, 0};
    gbl_helper.rowHeights = new int{20, 20};
    gbl_helper.columnWeights = new double{1.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
    gbl_helper.rowWeights = new double{0.0, 0};
    helper.setLayout(gbl_helper);

    GridBagConstraints gbc1 = new GridBagConstraints();
    gbc1.fill = GridBagConstraints.HORIZONTAL;
    gbc1.gridwidth = 2;
    gbc1.anchor = GridBagConstraints.NORTHWEST;
    gbc1.insets = new Insets(5,5,5,5);
    gbc1.gridx = 0;
    gbc1.gridy = 0;
    JButton button1 = new JButton( "Add puncta coordinates from CSV" );
    helper.add( button1, gbc1 );

    GridBagConstraints gbc2 = new GridBagConstraints();
    gbc2.fill = GridBagConstraints.HORIZONTAL;
    gbc2.gridwidth = 2;
    gbc2.anchor = GridBagConstraints.NORTHWEST;
    gbc2.insets = new Insets(5,5,5,5);
    gbc2.gridx = 2;
    gbc2.gridy = 0;
    JButton button2 = new JButton( "Add track coordinates from CSV" );

    helper.add( button2, gbc2 );

    GridBagConstraints gbc3 = new GridBagConstraints();
    gbc3.insets = new Insets(0, 0, 0, 5);
    gbc3.gridx = 0;
    gbc3.gridy = 1;
    JLabel label = new JLabel( "Move to time:" );
    helper.add( label, gbc3 );

    JTextField tMoveTime = new JTextField();
    tMoveTime.setColumns(15);
    GridBagConstraints gbc4 = new GridBagConstraints();
    gbc4.anchor = GridBagConstraints.WEST;
    gbc4.insets = new Insets(0, 0, 0, 5);
    gbc4.gridx = 1;
    gbc4.gridy = 1;
    helper.add( tMoveTime, gbc4);

    JButton bMoveTime = new JButton("Move");
    GridBagConstraints gbc5 = new GridBagConstraints();
    gbc5.insets = new Insets(0, 0, 0, 5);
    gbc5.anchor = GridBagConstraints.NORTHEAST;
    gbc5.gridx = 3;
    gbc5.gridy = 1;
    helper.add( bMoveTime, gbc5 );


    enter image description here



    A different approach is to divide a complex layout to simpler layouts by using sub - panels, each with it's own layout manager:



    enter image description here



        JPanel helper = new JPanel(  );
    helper.setLayout(new BoxLayout(helper, BoxLayout.Y_AXIS));
    getContentPane().add(helper);

    JPanel topPanel = new JPanel();
    helper.add(topPanel);
    JButton button1 = new JButton( "Add puncta coordinates from CSV" );
    topPanel.add(button1);
    JButton button2 = new JButton( "Add track coordinates from CSV" );
    topPanel.add(button2);

    JPanel bottomPanel = new JPanel();
    helper.add(bottomPanel);
    bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

    JPanel bottomRIght = new JPanel();
    bottomPanel.add(bottomRIght);
    JLabel label = new JLabel( "Move to time:" );
    bottomRIght.add(label);
    JTextField tMoveTime = new JTextField();
    bottomRIght.add(tMoveTime);
    tMoveTime.setColumns(15);

    JPanel bottomleftPanel = new JPanel();
    bottomPanel.add(bottomleftPanel);
    bottomleftPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
    JButton bMoveTime = new JButton("Move");
    bottomleftPanel.add(bMoveTime);


    enter image description here






    share|improve this answer






























      1














      You can consider two basic approaches :
      One is to use highly flexible layout manager, like MigLayout. I am not familiar with it, but I can recommend GridbagLayout for the job:



          JPanel helper = new JPanel(  );
      GridBagLayout gbl_helper = new GridBagLayout();
      gbl_helper.columnWidths = new int{200, 7, 200, 60, 18, 0};
      gbl_helper.rowHeights = new int{20, 20};
      gbl_helper.columnWeights = new double{1.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
      gbl_helper.rowWeights = new double{0.0, 0};
      helper.setLayout(gbl_helper);

      GridBagConstraints gbc1 = new GridBagConstraints();
      gbc1.fill = GridBagConstraints.HORIZONTAL;
      gbc1.gridwidth = 2;
      gbc1.anchor = GridBagConstraints.NORTHWEST;
      gbc1.insets = new Insets(5,5,5,5);
      gbc1.gridx = 0;
      gbc1.gridy = 0;
      JButton button1 = new JButton( "Add puncta coordinates from CSV" );
      helper.add( button1, gbc1 );

      GridBagConstraints gbc2 = new GridBagConstraints();
      gbc2.fill = GridBagConstraints.HORIZONTAL;
      gbc2.gridwidth = 2;
      gbc2.anchor = GridBagConstraints.NORTHWEST;
      gbc2.insets = new Insets(5,5,5,5);
      gbc2.gridx = 2;
      gbc2.gridy = 0;
      JButton button2 = new JButton( "Add track coordinates from CSV" );

      helper.add( button2, gbc2 );

      GridBagConstraints gbc3 = new GridBagConstraints();
      gbc3.insets = new Insets(0, 0, 0, 5);
      gbc3.gridx = 0;
      gbc3.gridy = 1;
      JLabel label = new JLabel( "Move to time:" );
      helper.add( label, gbc3 );

      JTextField tMoveTime = new JTextField();
      tMoveTime.setColumns(15);
      GridBagConstraints gbc4 = new GridBagConstraints();
      gbc4.anchor = GridBagConstraints.WEST;
      gbc4.insets = new Insets(0, 0, 0, 5);
      gbc4.gridx = 1;
      gbc4.gridy = 1;
      helper.add( tMoveTime, gbc4);

      JButton bMoveTime = new JButton("Move");
      GridBagConstraints gbc5 = new GridBagConstraints();
      gbc5.insets = new Insets(0, 0, 0, 5);
      gbc5.anchor = GridBagConstraints.NORTHEAST;
      gbc5.gridx = 3;
      gbc5.gridy = 1;
      helper.add( bMoveTime, gbc5 );


      enter image description here



      A different approach is to divide a complex layout to simpler layouts by using sub - panels, each with it's own layout manager:



      enter image description here



          JPanel helper = new JPanel(  );
      helper.setLayout(new BoxLayout(helper, BoxLayout.Y_AXIS));
      getContentPane().add(helper);

      JPanel topPanel = new JPanel();
      helper.add(topPanel);
      JButton button1 = new JButton( "Add puncta coordinates from CSV" );
      topPanel.add(button1);
      JButton button2 = new JButton( "Add track coordinates from CSV" );
      topPanel.add(button2);

      JPanel bottomPanel = new JPanel();
      helper.add(bottomPanel);
      bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

      JPanel bottomRIght = new JPanel();
      bottomPanel.add(bottomRIght);
      JLabel label = new JLabel( "Move to time:" );
      bottomRIght.add(label);
      JTextField tMoveTime = new JTextField();
      bottomRIght.add(tMoveTime);
      tMoveTime.setColumns(15);

      JPanel bottomleftPanel = new JPanel();
      bottomPanel.add(bottomleftPanel);
      bottomleftPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
      JButton bMoveTime = new JButton("Move");
      bottomleftPanel.add(bMoveTime);


      enter image description here






      share|improve this answer




























        1












        1








        1







        You can consider two basic approaches :
        One is to use highly flexible layout manager, like MigLayout. I am not familiar with it, but I can recommend GridbagLayout for the job:



            JPanel helper = new JPanel(  );
        GridBagLayout gbl_helper = new GridBagLayout();
        gbl_helper.columnWidths = new int{200, 7, 200, 60, 18, 0};
        gbl_helper.rowHeights = new int{20, 20};
        gbl_helper.columnWeights = new double{1.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
        gbl_helper.rowWeights = new double{0.0, 0};
        helper.setLayout(gbl_helper);

        GridBagConstraints gbc1 = new GridBagConstraints();
        gbc1.fill = GridBagConstraints.HORIZONTAL;
        gbc1.gridwidth = 2;
        gbc1.anchor = GridBagConstraints.NORTHWEST;
        gbc1.insets = new Insets(5,5,5,5);
        gbc1.gridx = 0;
        gbc1.gridy = 0;
        JButton button1 = new JButton( "Add puncta coordinates from CSV" );
        helper.add( button1, gbc1 );

        GridBagConstraints gbc2 = new GridBagConstraints();
        gbc2.fill = GridBagConstraints.HORIZONTAL;
        gbc2.gridwidth = 2;
        gbc2.anchor = GridBagConstraints.NORTHWEST;
        gbc2.insets = new Insets(5,5,5,5);
        gbc2.gridx = 2;
        gbc2.gridy = 0;
        JButton button2 = new JButton( "Add track coordinates from CSV" );

        helper.add( button2, gbc2 );

        GridBagConstraints gbc3 = new GridBagConstraints();
        gbc3.insets = new Insets(0, 0, 0, 5);
        gbc3.gridx = 0;
        gbc3.gridy = 1;
        JLabel label = new JLabel( "Move to time:" );
        helper.add( label, gbc3 );

        JTextField tMoveTime = new JTextField();
        tMoveTime.setColumns(15);
        GridBagConstraints gbc4 = new GridBagConstraints();
        gbc4.anchor = GridBagConstraints.WEST;
        gbc4.insets = new Insets(0, 0, 0, 5);
        gbc4.gridx = 1;
        gbc4.gridy = 1;
        helper.add( tMoveTime, gbc4);

        JButton bMoveTime = new JButton("Move");
        GridBagConstraints gbc5 = new GridBagConstraints();
        gbc5.insets = new Insets(0, 0, 0, 5);
        gbc5.anchor = GridBagConstraints.NORTHEAST;
        gbc5.gridx = 3;
        gbc5.gridy = 1;
        helper.add( bMoveTime, gbc5 );


        enter image description here



        A different approach is to divide a complex layout to simpler layouts by using sub - panels, each with it's own layout manager:



        enter image description here



            JPanel helper = new JPanel(  );
        helper.setLayout(new BoxLayout(helper, BoxLayout.Y_AXIS));
        getContentPane().add(helper);

        JPanel topPanel = new JPanel();
        helper.add(topPanel);
        JButton button1 = new JButton( "Add puncta coordinates from CSV" );
        topPanel.add(button1);
        JButton button2 = new JButton( "Add track coordinates from CSV" );
        topPanel.add(button2);

        JPanel bottomPanel = new JPanel();
        helper.add(bottomPanel);
        bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

        JPanel bottomRIght = new JPanel();
        bottomPanel.add(bottomRIght);
        JLabel label = new JLabel( "Move to time:" );
        bottomRIght.add(label);
        JTextField tMoveTime = new JTextField();
        bottomRIght.add(tMoveTime);
        tMoveTime.setColumns(15);

        JPanel bottomleftPanel = new JPanel();
        bottomPanel.add(bottomleftPanel);
        bottomleftPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
        JButton bMoveTime = new JButton("Move");
        bottomleftPanel.add(bMoveTime);


        enter image description here






        share|improve this answer















        You can consider two basic approaches :
        One is to use highly flexible layout manager, like MigLayout. I am not familiar with it, but I can recommend GridbagLayout for the job:



            JPanel helper = new JPanel(  );
        GridBagLayout gbl_helper = new GridBagLayout();
        gbl_helper.columnWidths = new int{200, 7, 200, 60, 18, 0};
        gbl_helper.rowHeights = new int{20, 20};
        gbl_helper.columnWeights = new double{1.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
        gbl_helper.rowWeights = new double{0.0, 0};
        helper.setLayout(gbl_helper);

        GridBagConstraints gbc1 = new GridBagConstraints();
        gbc1.fill = GridBagConstraints.HORIZONTAL;
        gbc1.gridwidth = 2;
        gbc1.anchor = GridBagConstraints.NORTHWEST;
        gbc1.insets = new Insets(5,5,5,5);
        gbc1.gridx = 0;
        gbc1.gridy = 0;
        JButton button1 = new JButton( "Add puncta coordinates from CSV" );
        helper.add( button1, gbc1 );

        GridBagConstraints gbc2 = new GridBagConstraints();
        gbc2.fill = GridBagConstraints.HORIZONTAL;
        gbc2.gridwidth = 2;
        gbc2.anchor = GridBagConstraints.NORTHWEST;
        gbc2.insets = new Insets(5,5,5,5);
        gbc2.gridx = 2;
        gbc2.gridy = 0;
        JButton button2 = new JButton( "Add track coordinates from CSV" );

        helper.add( button2, gbc2 );

        GridBagConstraints gbc3 = new GridBagConstraints();
        gbc3.insets = new Insets(0, 0, 0, 5);
        gbc3.gridx = 0;
        gbc3.gridy = 1;
        JLabel label = new JLabel( "Move to time:" );
        helper.add( label, gbc3 );

        JTextField tMoveTime = new JTextField();
        tMoveTime.setColumns(15);
        GridBagConstraints gbc4 = new GridBagConstraints();
        gbc4.anchor = GridBagConstraints.WEST;
        gbc4.insets = new Insets(0, 0, 0, 5);
        gbc4.gridx = 1;
        gbc4.gridy = 1;
        helper.add( tMoveTime, gbc4);

        JButton bMoveTime = new JButton("Move");
        GridBagConstraints gbc5 = new GridBagConstraints();
        gbc5.insets = new Insets(0, 0, 0, 5);
        gbc5.anchor = GridBagConstraints.NORTHEAST;
        gbc5.gridx = 3;
        gbc5.gridy = 1;
        helper.add( bMoveTime, gbc5 );


        enter image description here



        A different approach is to divide a complex layout to simpler layouts by using sub - panels, each with it's own layout manager:



        enter image description here



            JPanel helper = new JPanel(  );
        helper.setLayout(new BoxLayout(helper, BoxLayout.Y_AXIS));
        getContentPane().add(helper);

        JPanel topPanel = new JPanel();
        helper.add(topPanel);
        JButton button1 = new JButton( "Add puncta coordinates from CSV" );
        topPanel.add(button1);
        JButton button2 = new JButton( "Add track coordinates from CSV" );
        topPanel.add(button2);

        JPanel bottomPanel = new JPanel();
        helper.add(bottomPanel);
        bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));

        JPanel bottomRIght = new JPanel();
        bottomPanel.add(bottomRIght);
        JLabel label = new JLabel( "Move to time:" );
        bottomRIght.add(label);
        JTextField tMoveTime = new JTextField();
        bottomRIght.add(tMoveTime);
        tMoveTime.setColumns(15);

        JPanel bottomleftPanel = new JPanel();
        bottomPanel.add(bottomleftPanel);
        bottomleftPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
        JButton bMoveTime = new JButton("Move");
        bottomleftPanel.add(bMoveTime);


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 2 at 13:22

























        answered Jan 2 at 13:00









        c0derc0der

        9,21651846




        9,21651846
































            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%2f53997402%2fcomplex-layout-of-multiple-components%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

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith