有关如何在Java swing和Awt中绘制此布局的任何提示

时间:2014-11-17 04:41:13

标签: java swing layout-manager

我正在尝试绘制一个类似于下图的布局。我从昨天晚上开始尝试,但我还没能做到。任何想法如何在Java swing中绘制这样的布局

This is the Image Similar like to draw

我尝试使用GridLayoutGridBagLayout进行绘制,但实际上我还没有得到它。

1 个答案:

答案 0 :(得分:1)

这是一个纯粹的GridBagLayout实现,但可以使用BorderLayout并将三个顶部面板放入他们自己的JPanel(使用GridBagLayout)a将其放入CENTER,底部面板位于SOUTH位置......

Layout

setLayout(new GridBagLayout());

JPanel main = createPanel(400, 400, Color.RED);
JPanel menu = createPanel(600, 100, Color.BLUE);
JPanel upper = createPanel(200, 300, Color.GREEN);
JPanel lower = createPanel(200, 100, Color.MAGENTA);

GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridheight = 2;
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
add(main, gbc);

gbc.gridx++;
gbc.gridy = 0;
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.fill = GridBagConstraints.BOTH;
add(upper, gbc);

gbc.gridy++;
add(lower, gbc);

gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 2;
gbc.weightx = 1;
add(menu, gbc);