Question: Can someone tell me how to add 3 buttons under the txtArea in the TextLine class present in this link : <https://stackoverflow.com/a/18780743/3649438>

I am new to GUI programming and I have problems in adding them. I tried to add JButtons to pane1 or contentPane, but it seems that the code automatically resizes the window and it is not possible to add the buttons. I just need to add simple JButton which I will edit with my own code.

My possible solution was the one of making a button (repeating the procedure for each button) in this way:

```
JButton cancelBtn = new JButton("Cancel");

```

and then add it to the panels in this way.

```
cancelBtn.setVisible(true);
contentPane.add(cancelBtn);

```

but when I run it, it doesn't display it. I tried many other different ways with no success.

Answer: 
Read Layout Manager from [here](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html) 

Run this code. It will solve your problem. But first read the basic tutorials of Swing.

```
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.JScrollPane;

public class TextLine extends JFrame {

    private JPanel contentPane;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    TextLine frame = new TextLine();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public TextLine() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        JLabel lblTextLineExample = new JLabel("Text Line Example");
        lblTextLineExample.setHorizontalAlignment(SwingConstants.CENTER);
        contentPane.add(lblTextLineExample, BorderLayout.NORTH);

        JButton btnCancel = new JButton("Cancel");
        contentPane.add(btnCancel, BorderLayout.SOUTH);

        JTextArea textArea = new JTextArea();
        JScrollPane scrollPane = new JScrollPane(textArea, 
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
                   JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        textArea.setRows(30);
        textArea.setColumns(50);
        TextLineNumber tln1 = new TextLineNumber(textArea);
        scrollPane.setRowHeaderView( tln1 );
        contentPane.add(scrollPane, BorderLayout.CENTER);
        pack();
    }

}

```
```
public test() {
        super("Title");
        JPanel panel = new JPanel();
        add(panel);

        JButton mybutton = new JButton("TEST BUTTON");
        getContentPane().add(mybutton);
    }

```