【发布时间】:2013-10-31 13:13:39
【问题描述】:
这就是我希望我的 JFrame 的样子:
________________________________________________________________________________
|Play - 0 x |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Score List: |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Mario: 100 |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Luigi: 50 |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waluigi: 20 |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Wario: 10 |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|Status: Ready! Score: 30 |
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
目前,每个元素的大小相同,基本上只是将中间和顶部/底部分开。 Play 是 Frame 的标题,%s 表示用户可以在其中玩游戏的 JPanel。 'Status: Ready' 是一个 JLabel,'Score: 30' 也是如此。分数列表是一个 JTextArea。
那么,我该如何设置这些元素的大小和位置呢?到目前为止,我会给你我的代码,也许你能告诉我哪里出错了。
this.add(playPanel);
this.add(scoreArea);
this.add(statusLabel);
this.add(scoreLabel);
this.setLayout(new GridLayout(2,2));
【问题讨论】:
-
发表 ASCII 艺术谈论 BorderLayout
-
我看不出如何使用
GridLayout实现该布局。我会转而寻找Nested Layout 或GridBagLayout或GroupLayout。
标签: java swing grid textarea grid-layout