JSplitPane in JLayeredPane

倖福魔咒の 提交于 2020-01-05 09:01:11

问题


I want the right content of an JSplitPane to fill the entire available space and the left content (panel) to be on top of the other panel. I was thinking about using a JLayeredPane to solve that problem but I couldn't get it to work. My class currently looks like this:

public class LayeredPane extends JLayeredPane {

  private Component topComponent;

  private Component mainComponent;

  public LayeredPane() {

    setLayout(new GridBagLayout());
  }
 public Component setTopComponent(Component c) {
    this.topComponent = c;
    if (topComponent != null) {
        topComponent.setVisible(true);
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1;
        gbc.weighty = 1;
        gbc.gridheight = GridBagConstraints.REMAINDER;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.VERTICAL;
        setLayer(c, DEFAULT_LAYER + 1);
        add(topComponent, gbc);
    }
    return topComponent;
}

public Component setMainComponent(Component c) {
    this.mainComponent = c;
    if (mainComponent != null) {
         mainComponent.setVisible(true);
         GridBagConstraints gbc = new GridBagConstraints();
         gbc.gridx = 0;
         gbc.gridy = 0;
         gbc.weightx = 1;
         gbc.weighty = 1;
         gbc.fill = GridBagConstraints.BOTH;
         add(mainComponent,gbc);
    }
    return mainComponent;
 }
}

来源:https://stackoverflow.com/questions/48163471/jsplitpane-in-jlayeredpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!