瀏覽代碼

no more flow :(

tarfeef101 6 年之前
父節點
當前提交
1b0e0fb7b4
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      assignments/a3/src/main/java/Gallery.java

+ 8 - 1
assignments/a3/src/main/java/Gallery.java

@@ -68,7 +68,14 @@ public class Gallery extends JPanel implements Observer, Serializable
   {
     if (model.getGrid())
     {
-      this.setLayout(new FlowLayout(10));
+      int unit = 200;
+      int total = this.getWidth();
+      if (items.size() > 0)
+      {
+        int unit = items.get(i).getWidth();
+      }
+      int cols = total / unit;
+      this.setLayout(new GridLayout(0, cols));
     }
     else
     {