GridLayout是以行作为优先考虑的因素的:
When both the number of rows and the number of columns have been set to non-zero values, either by a constructor or by the setRows and setColumns methods, the number of columns specified is ignored. Instead, the number of columns is determined from the specified number or rows and the total number of components in the layout. So, for example, if three rows and two columns have been specified and nine components are added to the layout, then they will be displayed as three rows of three columns. Specifying the number of columns affects the layout only when the number of rows is set to zero. 
你把行数设为0就可以了。
Specifying the number of columns affects the layout only when the number of rows is set to zero.

解决方案 »

  1.   

    把兩個label放到一個panel中應該好一點,再用FlowLayout:
    setLayout(null);//p1的父容器設為絕對座標
    Panel p1 = new Panel(new FlowLayout());//還要設置好panel的大小
    p1.setSize(300,200);
    p1.setLocation(0,0);
    p1.add(new Label("物料代碼"));
    p1.add(new Label("物料名稱"));
    add(p1);你要比較熟悉几種常用的佈局管理器:
    FlowLayout:流式佈局,從左至右,當一行擺滿後換一行繼續從左向右擺放
    GridLayout:網格佈局,將容器分成尺寸相同的網格,順序與FlowLayout一樣
    BorderLayout:邊緣佈局,可擺放"North","South","East","West","Center"
    CardLayout:將每個部件放在單獨的卡上,在某一時刻只有一個部件可見
    GridBagLayout:也是單元網格,但部件可以佔用多個單元
    null:空布局,可以在一定的座標上顯式的放置部件,需要setLocation,setSize
      

  2.   

    比较复杂的界面,我推荐你用GridBagLayout。