dcsimg
GridBagLayout & Canvas question
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mike_f
Posted On:   Saturday, December 16, 2006 02:37 PM

Hi! I hit a snag during my homework assignment. I am in the making of a RTS game, and want to draw on a Canvas, which I'm placing within a Panel that has a GridbagLayout using the following code: pane = new Panel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); //pane.add(new Label(), c); c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.BOTH; pane.add(field, c); As I understand this should place and size the field (Canvas) to fill out all the available space in the panel, but all I see is a big white nothing . The funny thing is that if I delete the comment tag before pane.add(new Label(), c); then I actually get what   More>>

Hi!

I hit a snag during my homework assignment. I am in the making of a RTS game, and want to draw on a Canvas, which I'm placing within a Panel that has a GridbagLayout using the following code:


			pane = new Panel(new GridBagLayout());
			
GridBagConstraints c = new GridBagConstraints();
//pane.add(new Label(), c);
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.BOTH;
pane.add(field, c);

As I understand this should place and size the field (Canvas) to fill out all the available space in the panel, but all I see is a big white nothing . The funny thing is that if I delete the comment tag before

pane.add(new Label(), c);
then I actually get what I wanted, the field (Canvas) is drawn correctly in the appropriate place and size (except for the label itself in the center of the window). Any ideas why is this happening?

Thanks in advance,
Mike

   <<Less

Re: GridBagLayout & Canvas question

Posted By:   WarnerJan_Veldhuis  
Posted On:   Saturday, December 16, 2006 02:43 PM

The easiest way to let a component fill the entire area is to either use no layoutmanager or a BorderLayout, which then gets a component in BorderLayout.CENTER. If you have to use a GridBagLayout, set GridBagConstraints.weightx and weighty to 1 for example
About | Sitemap | Contact