I am trying to match the following
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.
请参阅“ 如何使用BoxLayout” ,也许还有一些填充物和漂亮的斜角边框 。
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.