• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applied Reasoning Mock #34

 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question on Applied Reasoning's Mock:
True or false: Changing the width of a cell [in GridBagLayout] changes the width of all the cells in that particular row.
Answer given: false, it affects the column.
I said true. I mean, of course it affects the column in a controlled way. But surely the other cells in the row are affected too. If the panel is a set size, they'd have to squeeze or grow a bit to make up for the changes in the cell. N'est-ce pas???
Thanks
Eric
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the key here is "all of the cells".
It may be true that some cells may be affected, but not necessarily all.
Let's say that the column on the far left side of the panel has a weightx value of 0.5 (occupies half the x-axis space in the panel.). Let's say that the affected cell is in the column just to the right of this one. When the width of this cell is changed, it may change the sizes of the cells on that row to the right of the affected cell. However, the cell with a designated weightx value of 0.5 will NOT be affected (as far as I know) since the column is set to an explicit percentage of the panel's x-axis space.
 
Eric Barnhill
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote some code to check this, and it turns out neither of us are right! At least if I'm interpreting the code right.
First of all, the weightx is not a specific percentage, it could be a number above 1 for example, it just links with the other weights to work out a ratio. If only one cell has a weight value, whatever the amount, it takes up the rest of the extra space in the row.
So, given that, if I increase the size of one cell, the weighted cell will move - but I was still wrong. Because if cell is already at a minumum size, then it won't change, if there's anywhere to absorb the shock. Here's the code, if anyone's interested:
<pre>
import java.awt.*;
import java.awt.event.*;
public class TwoBags extends Frame {
Frame f;
Panel p1,p2;
GridBagLayout layout;
GridBagConstraints constraints;
Button left,center,right;
public TwoBags() {
super("Two GridBagLayouts");
//first panel
p1 = new Panel();
layout = new GridBagLayout();
p1.setLayout(layout);
constraints = new GridBagConstraints();
constraints.gridx=0;
constraints.gridy=0;
left = new Button("Left");
layout.setConstraints(left,constraints);
p1.add(left);
constraints.gridx=1;
center = new Button("Center");
layout.setConstraints(center,constraints);
p1.add(center);
constraints.gridx=2;
constraints.ipadx=0;
constraints.weightx=.5;
right = new Button("Right");
layout.setConstraints(right,constraints);
p1.add(right);
right=left=center=null;
//second panel
p2 = new Panel();
layout = new GridBagLayout();
p2.setLayout(layout);
constraints = new GridBagConstraints();
constraints.gridx=0;
constraints.gridy=0;
left = new Button("Left");
layout.setConstraints(left,constraints);
p2.add(left);
constraints.gridx=1;
//this time add ipad to center
constraints.ipadx=50;
center = new Button("Center");
layout.setConstraints(center,constraints);
p2.add(center);
constraints.gridx=2;
constraints.ipadx=0;
constraints.weightx=.5;
right = new Button("Right");
layout.setConstraints(right,constraints);
p2.add(right);
f = new Frame();
f.setLayout(new GridLayout(2,1));
f.setSize(300,300);
f.add(p1);
f.add(p2);
f.addWindowListener(
new WindowAdapter(){
public void WindowClosing(WindowEvent event) {
System.exit(0);
}
}
);
f.setVisible(true);
System.out.println(p1.getSize());
System.out.println(p2.getSize());
}
public static void main (String[] args) {
TwoBags tb = new TwoBags();
}
}

</pre>
Note that if the ipad is set really high, like 250, ALL other buttons are knocked out so they do move. So, the applet is right, but it is right under only two conditions:
- one col. is at min. size for an object in the col.
- there is extra space for other cols. to absorb (they are not at min size either), after the cell width is changed.
tricky, no?
Eric
[This message has been edited by Eric Barnhill (edited May 12, 2000).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic