📄 e622. creating a gridbaglayout.txt
字号:
e622. Creating a GridBagLayout
A gridbag layout is the most sophisticated layout manager in Java's UI toolkit. This example demonstrates how to create and set a gridbag layout and how to set gridbag constraints on components added to the layout. See other examples for code that demonstrates the usage of available gridbag constraints.
JFrame frame = new JFrame();
Container container = frame.getContentPane();
// Create the layout
GridBagLayout gbl = new GridBagLayout();
// Set layout on container
container.setLayout(gbl);
// Place a component at cell location (1,1)
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
// Add other gridbag constraints here
// Associate the gridbag constraints with the component
gbl.setConstraints(component, gbc);
// Add the component to the container
container.add(component);
// Show the frame
frame.pack();
frame.setVisible(true);
Related Examples
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -