if (myalign == LEFT) x = ins.left + hgap;
if (myalign == RIGHT) x = ins.left + (d.width - new_w) + hgap;
  public void layoutContainer (Container parent)  {    synchronized (parent.getTreeLock ())      {	int num = parent.getComponentCount ();	// This is more efficient than calling getComponents().	Component[] comps = parent.component;	Dimension d = parent.getSize ();	Insets ins = parent.getInsets ();	ComponentOrientation orient = parent.getComponentOrientation ();	boolean left_to_right = orient.isLeftToRight ();	int y = ins.top + vgap;	int i = 0;	while (i < num)	  {	    // Find the components which go in the current row.	    int new_w = ins.left + hgap + ins.right;	    int new_h = 0;	    int j;	    boolean found_one = false;	    for (j = i; j < num; ++j)	      {		// Skip invisible items.		if (! comps[j].visible)		  continue;		Dimension c = comps[j].getPreferredSize ();		int next_w = new_w + hgap + c.width;		if (next_w <= d.width || ! found_one)		  {		    new_w = next_w;		    new_h = Math.max (new_h, c.height);		    found_one = true;		  }		else		  {		    // Must start a new row, and we already found an item		    break;		  }	      }	    // Set the location of each component for this row.	    int x;	    int myalign = align;	    if (align == LEADING)	      myalign = left_to_right ? LEFT : RIGHT;	    else if (align == TRAILING)	      myalign = left_to_right ? RIGHT : LEFT;	    if (myalign == LEFT)	      x = ins.left + hgap;	    else if (myalign == CENTER)	      x = ins.left + (d.width - new_w) / 2 + hgap;	    else	      x = ins.left + (d.width - new_w) + hgap;	    for (int k = i; k < j; ++k)	      {		if (comps[k].visible)		  {		    Dimension c = comps[k].getPreferredSize ();		    comps[k].setBounds (x, y + (new_h - c.height) / 2,					c.width, c.height);		    x += c.width + hgap;		  }	      }	    // Advance to next row.	    i = j;	    y += new_h + vgap;	  }      }  }