e623. setting the location of a component in a gridbaglayout.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 21 行

TXT
21
字号
 gridbag layout arranges components in a two-dimensional grid of cells. The northwest-most cell has position (0,0). The cell to the right or east has position (1,0); the cell to the bottom or south has position (0,1). 
The size of the grid grows dynamically. For example, if you place a component at position (2,1) in a new empty gridbag layout, the layout will automatically have a size of 3 cells across by 2 cells down. 

See e622 Creating a GridBagLayout for an example on how to use a gridbag layout with gridbag constraints. 

    GridBagConstraints gbc = new GridBagConstraints();
    
    // Place a component at (1,1)
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbl.setConstraints(component1, gbc);
    container.add(component1);
    // The layout now has 4 cells
    
    // Place a component at (0,0)
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbl.setConstraints(component2, gbc);
    container.add(component2);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?