本文介绍了带有GridBagLayout的各种网格大小和JPanel元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试匹配以下内容
I am trying to match the following
在实现GridBagLayout时. GBL是我知道我可以获得不同大小的元素的唯一方法.我知道我可以做类似上图的操作,但是我不知道如何使用GBL.我也准备就更好的主意提出建议.
while implementing a GridBagLayout. The GBL is the only way I know i can get the different sized elements. I know I can do something like the above picture but I don't know how to do it with GBL. I am also ready to take suggestions on a better idea.
推荐答案
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
class PlayerGui {
public static void main(String[] args) {
JPanel gui = new JPanel(new BorderLayout());
gui.setBorder(new BevelBorder(BevelBorder.RAISED));
JPanel north = new JPanel(new GridLayout(0,1,5,5));
north.add(new JLabel("Player Name", SwingConstants.CENTER));
JPanel tfConstrain = new JPanel(new FlowLayout(FlowLayout.CENTER));
tfConstrain.add(new JTextField(18));
north.add(tfConstrain);
gui.add(north, BorderLayout.NORTH);
JPanel center = new JPanel(new GridLayout(0,1,10,10));
center.add(new JButton("On This Machine"));
center.add(new JButton("Netowrk Based"));
center.add(new JButton("Main Menu"));
center.setBorder(new EmptyBorder(40,70,40,70));
gui.add(center, BorderLayout.CENTER);
JOptionPane.showMessageDialog(null, gui);
}
}
这篇关于带有GridBagLayout的各种网格大小和JPanel元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!