示例#1
0
 public void sizeToText() {
   Dimension d = new Dimension(0, 0);
   Dimension di;
   for (int i = 0; i < nLists; i++) {
     fm = getFontMetrics(list[i].getFont());
     di = list[i].preferredSize();
     d.height += di.height;
     for (int j = 0; j < list[i].countItems(); j++) {
       d.width = Math.max(d.width, fm.stringWidth(list[i].getItem(j) + "  "));
     }
   }
   for (int i = 0; i < nLists; i++) {
     list[i].resize(d.width + hSpace / 3, list[i].preferredSize().height);
   }
   panel.resize(d.width + hSpace / 3, list[1].preferredSize().height);
   this.resize(d.width + hSpace, d.height + vSpace);
   panel.invalidate();
   validate();
 }