问题
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