小编Jos*_*ock的帖子

如何将JPanel中的组件对齐到左侧?

我已经为基本的文本编辑器创建了一个布局,我希望顶部栏的左边是按钮,顶栏是JPanel,它使用的是FlowLayout管理器.它使用GridBag布局管理器在网格内部.有什么建议?

import java.awt.*;
import javax.swing.*;

public class GridTest {
private static JButton firstButton, secondButton, thirdButton;
private static JPanel panel, sidebar, infoPanel;
private static JTextArea textArea;

public static void addComponentsToPane(Container container) {
    container.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    firstButton = new JButton("Button 1");
    secondButton = new JButton("Button 2");
    thirdButton = new JButton("Button 3");

    panel = new JPanel(new FlowLayout());
    sidebar = new JPanel(new FlowLayout());
    infoPanel = new JPanel(new FlowLayout());

    textArea = new JTextArea("This is some generic text!");

    c.fill = GridBagConstraints.HORIZONTAL;
    c.ipady …
Run Code Online (Sandbox Code Playgroud)

java layout swing jpanel

6
推荐指数
2
解决办法
1088
查看次数

标签 统计

java ×1

jpanel ×1

layout ×1

swing ×1