相关疑难解决方法(0)

JSeparator不会显示GridBagLayout

我想使用GridBagLayout在两个组件之间添加一个垂直JSeparator.我的代码如下:

public MainWindowBody(){
    setLayout(new GridBagLayout());

    JPanel leftPanel = new InformationPanel();
    JPanel rightPanel = new GameSelectionPanel();

    JSeparator sep = new JSeparator(JSeparator.VERTICAL);
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.NORTH;

    add(leftPanel,gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.VERTICAL;

    add(sep,gbc);

    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.NONE;

    add(rightPanel,gbc);
}
Run Code Online (Sandbox Code Playgroud)

但JSeperator没有显示任何想法?

谢谢

java user-interface swing gridbaglayout

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

gridbaglayout ×1

java ×1

swing ×1

user-interface ×1