Results 1 to 2 of 2
Thread: Problem with GridBagLayout.
- 05-26-2012, 02:42 PM #1
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
Problem with GridBagLayout.
Hi,
I'm using the GridBagLayout manager and i want to add my first button at the left corener of my frame (0,0).
The button locate him self to the center of my frame, and i dont know how to move it to the left corener.
This is what i want to do :

I want to locate the button at the red place.
This is my code :
How do i use the GridBagLayout to locate the button there?Java Code:import javax.swing.*; import java.awt.*; public class Display { private JFrame frame; private JPanel panel; private JList<String> list; public Display() { frame = new JFrame(); panel = new JPanel(new GridBagLayout()); list = new JList<String>(); frame.setVisible(true); frame.setSize(600,600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridBagConstraints grid = new GridBagConstraints(); //Set the spaces between the components and order them VERTICAL. grid.fill = GridBagConstraints.VERTICAL; grid.insets = new Insets(15,15,15,15); int day_of_week = 7; for(int i=0;i<28;i++) { grid.gridx = i % 7; grid.gridy = i / 7 ; list = new JList<String>(); panel.add(list,grid); } frame.add(panel); } }
Thanks alot,
Or.
-
Re: Problem with GridBagLayout.
You're not setting all the pertinent fields of the GridBagConstraints object. Look at the API and the tutorial. For example you'll want to set the weight constraints among others.
Similar Threads
-
GridBagLayout Component Problem...
By danpotter in forum AWT / SwingReplies: 5Last Post: 05-09-2012, 11:34 PM -
GridBagLayout alignment problem
By adwart in forum AWT / SwingReplies: 2Last Post: 08-15-2011, 04:58 AM -
GridBagLayout problem!
By canersen in forum AWT / SwingReplies: 9Last Post: 03-06-2011, 11:35 PM -
Problem with GridBagLayout
By ze snow in forum New To JavaReplies: 20Last Post: 02-28-2010, 06:08 AM -
Problem with GridBagLayout
By Daniel in forum SWT / JFaceReplies: 2Last Post: 07-01-2007, 06:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks