I created a Panel(ex: TopPanel) and set the layout of the panel to GridLayout(1,2).
And the panel (TopPanel) has two components. The components are also other panels(ex: TopPanel1 and TopPanel2).
Actually the problem is--- "I need to set the first component(TopPanel1) width to 75% of the TopPanel and other 25 % of the will take the TopPanel2".
I am using GridLayout, so the components (cell) will get equal width and height.
Is there any way to solve my problem with the GridLayout.
I not very flexible in using GridBagLayout, so that I need to with GridLayout.
You said it yourself: GridLayout will divide the space equally between the components. You can't change that, that's just how it works.
Apart from GridBagLayout, I can't think of any layout manager that can do this. However, GridBagLayout is not that hard for this:
The only problem with this code is that the 75% - 25% will only kick in after the frame is resized enough. That's because it uses the preferred size of the buttons as the initial size. You can fix that by calling setPreferredSize on your components.