0

This panel is used to organize everything this method does. It is inside a JFrame and everything works perfectly except that the positioning inside this one JPanel, which has it staggered(from left to right, there is showQuestionsPanel, new line aligned with bottom right of that we have the addQuestionPanel, then aligned with the bottom of the showquestions panel but to the right of the addQuestionsPanel we have the closeEQPanel, and to the right of that but below the addQuestionsPanel is the eqbuttonPanel). The closeEQPanel should be the top right panel, with showQuestionsPanel to its left, and immediately below should be the addQuestionPanel on the left with the eqbuttonPanel to the right, all aligned as a 2x2 grid. What do I have wrong in this layout?

//arrange visual elements/create main panel            
JPanel mainEQPanel = new JPanel();
GroupLayout eqLayout = new GroupLayout(mainEQPanel);
mainEQPanel.setLayout(eqLayout);
eqLayout.setAutoCreateGaps(true);
eqLayout.setAutoCreateContainerGaps(true);
eqLayout.setHorizontalGroup(
    eqLayout.createSequentialGroup()
        .addGroup(eqLayout.createParallelGroup(GroupLayout.Alignment.TRAILING))
            .addComponent(showQuestionsPanel)
            .addComponent(addQuestionPanel)
        .addGroup(eqLayout.createParallelGroup(GroupLayout.Alignment.CENTER))
            .addComponent(closeEQPanel)   
            .addComponent(eqbuttonPanel)
);      
eqLayout.setVerticalGroup(
        eqLayout.createSequentialGroup()
        .addGroup(eqLayout.createParallelGroup(GroupLayout.Alignment.LEADING))
            .addComponent(showQuestionsPanel)
            .addComponent(closeEQPanel)
        .addGroup(eqLayout.createParallelGroup(GroupLayout.Alignment.LEADING))
            .addComponent(addQuestionPanel)
            .addComponent(eqbuttonPanel)
);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). 2) Provide ASCII art or a simple drawing of the layout of the GUI at minimum size, and if resizable, with more width and height. 3) See also [this MCVE](http://stackoverflow.com/a/21659516/418556) for aligning rows of label/field pairs. – Andrew Thompson Jun 08 '15 at 09:24

1 Answers1

2

You are almost there, your problem is that you never assign anything to your ParallelGroup, your bracer/bracket is in the wrong spot:

.addGroup(eqLayout.createParallelGroup(GroupLayout.Alignment.TRAILING))//NOTE THE CLOSE BRACKET HERE
.addComponent(showQuestionsPanel)
.addComponent(addQuestionPanel)

But you need:

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
        .addComponent(showQuestionsPanel)
        .addComponent(addQuestionPanel))//NOTE THE CLOSE BRACKET HERE INSTEAD
sorifiend
  • 5,927
  • 1
  • 28
  • 45