Skip to content
Advertisement

Grid not working in java swing and getting overflowed

I have a Jframe and I want to show grids as follows:

https://i.stack.imgur.com/UmXPJ.png

There are 3rows and in the 2nd row there are two columns.So,but when I add a Jlabel and Jtextfield in 2nd row,then the 2nd column of 2nd grid goes below the 2nd row and acts as 3rd column. For eg:

https://i.stack.imgur.com/X0qUZ.png

So "hello55" needs to come side by side of the 2nd row,but it is coming downward as extra row in swing. How can I make it side to side?

So,I tried as:

JavaScript

Advertisement

Answer

The below code simply sets up your desired GUI and nothing more. It is not a complete, working application. Explanations after the code.

JavaScript

The default layout manager for the content pane of JFrame is BorderLayout. So I placed the hello11 as the top component and the hello33 as the bottom component.

In the center component I put a panel and set its layout manager to GridLayout so that I could nest within it two panels side by side where the left panel is your form and the right panel is hello55.

For the panel displaying the [login] form, I used GridBagLayout.

Here is a screen capture of the window displayed when running the above code.

Admin_Dashboard

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement