I create a JPanel and I want to have two columns in it. So I used grid layout with single row and two columns. Here myToolWindow is a JPanel. box and countermeasure_box should display inside this 2 columns. The following is my code and its output. As you can see it contains 3 columns and expected output spread only through 2/3 of the window width instead of displaying 2 boxes within two columns. Can anyone help to solve this problem ?