
Make Different List Items Look Different #16
Chapter 2, Lists and Combos
|
75
HACK
// image
imageCellPrototype = new JPanel( );
imageCellPrototype.setLayout (new GridBagLayout( ));
addWithGridBag (new JLabel(imageFileIcon), imageCellPrototype,
0, 0, 1, 2,
GridBagConstraints.WEST,
GridBagConstraints.BOTH, 0, 0);
imageNameLabel = new JLabel( );
imageNameLabel.setFont (nameFont);
addWithGridBag (imageNameLabel, imageCellPrototype,
1, 0, 1, 1,
GridBagConstraints.NORTH,
GridBagConstraints.HORIZONTAL, 1, 0);
imageSizeLabel = new JLabel( );
addWithGridBag (imageSizeLabel, imageCellPrototype,
1, 1, 1, 1,
GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL,
1, 0);
imageIconLabel = new JLabel( );
addWithGridBag (imageIconLabel, imageCellPrototype,
2, 0, 1, 2,
GridBagConstraints.EAST,
GridBagConstraints.VERTICAL, 0, 0);
opacify (imageCellPrototype);
}
private void addWithGridBag (Component comp, Container cont,
int x, int y,
int width, int height,
int anchor, int fill,
int weightx, int weighty) {
GridBagConstraints gbc = new GridBagConstraints( );
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = width;
gbc.gridheight = height;
gbc.anchor = anchor;
gbc.fill = fill;
gbc.weightx = weightx;
gbc.weighty = weighty;
cont.add (comp, gbc);
}
private void opacify (Container prototype) {
Component[] comps = prototype.getComponents( );
for (int i=0; i<comps.length; i++) {
if (comps[i] instanceof JComponent) ...