GridBagLayout & setting JPanel to appear in specific location


I am using the gridbagLayout. I have a JPanel, a JTable, and another JPanel in that appear in that order down the screen.
The problem is, I want the first JPanel to appear nearer the top left hand corner of the screen, It appears 1/2 way down the screen. Which forces the JTable further down.
Can I fix the setting of this JPanel.
I tried setLocation(10,10); but it didnt solve it for me.

Could anyone offer advice.

Who is Participating?
HemanthaKumarConnect With a Mentor Commented:
To distribute the objects ,  set weighty to 1 in the GridBagConstraints

You'll need to post your code, preferably runnable
Mayank SAssociate Director - Product EngineeringCommented:
Did you put it in a scroll-pane? If yes, then you need to set the location/ bounds to the scroll-pane (not to the panel).
> I tried setLocation(10,10); but it didnt solve it for me.

to set the location you need to use null layout manager.
And you'll also need to set the size
ShamDAuthor Commented:
Thanks for your responses.
I just needed to alter my GridbagConstraints inputs.
I wasnt sure how to use them before and what they all meant.
All Courses

From novice to tech pro — start learning today.