Tôi muốn thêm một JSeparator dọc giữa hai thành phần sử dụng GridBagLayout. Mã tôi có như sau:JSeparator sẽ không hiển thị với GridBagLayout
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);
}
Nhưng JSeperator không hiển thị, bất kỳ ý tưởng nào?
Cảm ơn
Các JSeperator không thực sự "hiển thị", có một dòng mỏng giữa các thành phần sẽ biến mất nếu bạn nhận xét thêm (sep, gbc) – Thomas