Java Reference
In-Depth Information
screenshot. As you can see in the picture, in contrast to the original application, more space is
distributed to the items and less to the amounts, resulting in a more adequate layout.
Figure 4.11. The
ShoppingChart2
application using the
TableLayout
.
Listing 4.11
TableLayout.java
public class TableLayout implements LayoutManager {
int cols;
public void addLayoutComponent (String where, Component component)
{
}
public void removeLayoutComponent (Component component) {
}
public TableLayout (int cols) {
this.cols = cols;
if (cols < 1)
throw new RuntimeException
("cols must be > 0");
}
public Dimension getMinimumSizes (Container container,
int [] mcw, int [] mrh) {
int count = container.getComponentCount();
Dimension sum = new Dimension (0, 0);
int i = 0;
for (int y = 0; y < mrh.length; y++) {
for (int x = 0; x < cols && i < count; x ++) {
Dimension ms = container.getComponent
(i++).getMinimumSize();
mcw [x] = Math.max (mcw [x], ms.width);
Search WWH ::
Custom Search