Trying to align JPanel to top-left of JFrame using GridBagLayout
Hi,
I'm creating an application that makes use of the GridBagLayout as it is the most useful layout manager for what I need. I made a JPanel and added it to the frame. The result I'm currently getting during run-time is a JFrame with a JPanel placed in the center. Now, I know that when using GridBagLayout all components are center aligned by default so I am trying to align my JPanel to the top-left of the frame. I have made many attempts at solving my problem including use of the lines: c.NORTHWEST; and also myJPanel.setLayout(0,0);
with no success. If possible would anyone be kind enough to assist me in resolving my problem? I have included a small amount of code that is not my own but is similar if it helps to visualize. Thank you.
setLayout( new BorderLayout() );
GridBagLayout gridbag = new GridBagLayout();
JPanel frame = new JPanel(gridbag);
add(panel, BorderLayout.NORTH );
frame.add( ... ); // add your GridBagLayout Components to frame to align them to top