JSeparator wont show with GridBagLayout

前端 未结 2 950
北恋
北恋 2021-01-12 02:51

I want to add a vertical JSeparator between two components using a GridBagLayout. The code I have is as follows:

public MainWindowBody(){
    setLayout(new G         


        
2条回答
  •  清歌不尽
    2021-01-12 03:03

    You could try to set the preferred width for the separator:

    sep.setPreferredSize(new Dimension(5,1));
    

    Then, make GridBagLayout use up all available height for the separator:

    gbc.fill = GridBagConstraints.VERTICAL;
    gbc.weighty = 1;
    

提交回复
热议问题