我想使用 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);
}
但是 JSeperator 没有显示,有什么想法吗?
谢谢