title: Using GroupLayout and FlowLayout together : OutPut is not appearing in Center
body: <p>I am trying to create a UI in Java swing with Layouts. I want radio buttons and 2 texts field and buttons. For radio buttons, I have used Flow layout and for text fields and button I am using Group layout. But output I am getting is scattered and the text fields are stretched. I want all these components at the center of the window. Following is my code.</p>
  
  <pre><code>  package DecodeTool1;
  
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
  
        public class SwingLayoutDemo {
            private JFrame mainFrame;
              private JLabel file_1;
            private JLabel file_2;
          private JPanel RPanel;
           private JPanel TextPanel;
  
           private JPanel panel;
  
  
           public SwingLayoutDemo(){
                  prepareGUI();
           }
                public static void main(String[] args){
              SwingLayoutDemo swingLayoutDemo = new SwingLayoutDemo();  
              swingLayoutDemo.showGroupLayoutDemo();       
         }
         private void prepareGUI(){
            mainFrame = new JFrame("Java SWING Examples");
           mainFrame.setSize(400,400);
                mainFrame.setLayout(new GridLayout(3, 2,20,10));
  
  
    file_1 = new JLabel("",JLabel.CENTER);
    file_2 = new JLabel("",JLabel.CENTER);        
    file_2.setSize(100,100);
  
               mainFrame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent windowEvent){
                   System.exit(0);
                   }        
            });    
           panel = new JPanel();
  
            TextPanel = new JPanel();
              mainFrame.add(file_1);
             mainFrame.add(file_2);
  
            mainFrame.setVisible(true);  
        }
          private void showGroupLayoutDemo(){
  
  
             RPanel = new JPanel();
             RPanel.setSize(50,50);
              RPanel.setBounds(150, 0, 50, 50);
             TextPanel = new JPanel();
               TextPanel.setSize(50,50);
  
  
              JRadioButton r1=new JRadioButton("Airport");  
              JRadioButton r2 = new JRadioButton("Apex");
              JRadioButton r3 = new JRadioButton("IN");
               ButtonGroup bg=new ButtonGroup();    
  
               FlowLayout layoutFL = new FlowLayout();
                layoutFL.setAlignment(FlowLayout.CENTER);
                  RPanel.setLayout(layoutFL);
                 layoutFL.setHgap(15);
  
                   RPanel.add(bg);
  
                   RPanel.add(comboApex);
  
                 RPanel.add(comboINAV);
  
  
                 file_1.setText("File1");  
                  file_2.setText("File2");
                  JTextField text1 = new JTextField(10);
                  JTextField text2 = new JTextField(10);
                     text1.setSize(15, 5);
                    text2.setSize(15,5);
  
  
                    GroupLayout layout = new GroupLayout(TextPanel);
                layout.setAutoCreateGaps(true);
               layout.setAutoCreateContainerGaps(true);
  
  
                 JButton btn1 = new JButton("Browse");
                    JButton btn2 = new JButton("Browse");
  
  
  
                layout.setHorizontalGroup(layout.createSequentialGroup()
                  //  .addGroup(layout.createSequentialGroup()
       .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
  
       .addComponent(file_1)  
       .addComponent(file_2))
       .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)  
       .addComponent(text1)
       .addComponent(text2))
  
            .addGroup(layout.createParallelGroup(
            GroupLayout.Alignment.CENTER)
  
               .addComponent(btn1))
           .addComponent(btn2)
  
            .addGroup(layout.createSequentialGroup()
               .addComponent(btn3)));
  
  
  
             layout.setVerticalGroup(layout.createSequentialGroup()
  
       .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(file_1)  
            .addComponent(text1)
            .addComponent(btn1))
            .addComponent(btn3)
  
        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)  
               .addComponent(file_2)
                       .addComponent(text2)
                       .addComponent(btn2)));
  
  
  
                  TextPanel.setLayout(layout); 
  
                 mainFrame.add(RPanel);
               mainFrame.add(TextPanel);
                mainFrame.add(panel);
  
                mainFrame.pack();
  
                   mainFrame.setVisible(true);  
  
        }    
        }
  </code></pre>