Prophet05
Erfahrenes Mitglied
Hallo,
ich habe ein JPanel in das ich verschiedene Komponenten mit einem GridBagLayout verpacke. Unter anderem auch eine JList. Wenn ich die JList nun so in das GridBagLayout einfüge ist sie wie gewollt sichtbar und nimmt so viel platz ein wie sei bekommen kann. Wenn ich die JList jetzt aber in ein JScrollPane verpacke verschwindet sie gänzlich und ich sehe sie gar nicht. Ich verstehe nicht warum. Hier des entscheidende Ausschnitt aus meinem Quelltext:
Die besagte Liste ist this.uiOceanObjectList.
ich habe ein JPanel in das ich verschiedene Komponenten mit einem GridBagLayout verpacke. Unter anderem auch eine JList. Wenn ich die JList nun so in das GridBagLayout einfüge ist sie wie gewollt sichtbar und nimmt so viel platz ein wie sei bekommen kann. Wenn ich die JList jetzt aber in ein JScrollPane verpacke verschwindet sie gänzlich und ich sehe sie gar nicht. Ich verstehe nicht warum. Hier des entscheidende Ausschnitt aus meinem Quelltext:
Code:
public OceanControlPanel() {
this.uiOceanObjectList = new JList();
this.uiRemoveObjectButton = new JButton("Remove");
this.uiAddObjectButton = new JButton("Add");
this.uiStartStopSimButton = new JButton("Start");
this.uiOceanPanel = new OceanPanel();
this.initLayout();
}
/**
* Initializes the layout of the components on the panel.
*/
private void initLayout() {
this.setLayout(new BorderLayout());
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false);
splitPane.setLeftComponent(new JScrollPane(this.uiOceanPanel));
// Setup the panel with the control items of the ocean.
JPanel controlPanel = new JPanel();
controlPanel.add(this.uiStartStopSimButton);
controlPanel.add(this.uiAddObjectButton);
controlPanel.add(this.uiRemoveObjectButton);
controlPanel.add(this.uiOceanObjectList);
// Set the layout of the control panel.
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
controlPanel.setLayout(gbl);
// Basic settings
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.insets = new Insets(3,3,3,3);
constraints.weightx = 1.0;
constraints.weighty = 0.0;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.gridy = 0;
gbl.addLayoutComponent(this.uiStartStopSimButton, constraints);
constraints.gridy = 1;
gbl.addLayoutComponent(this.uiAddObjectButton, constraints);
constraints.gridy = 2;
gbl.addLayoutComponent(this.uiRemoveObjectButton, constraints);
constraints.gridy = 3;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
// So verschwindet sie plötzlich:
//gbl.addLayoutComponent(new JScrollPane(this.uiOceanObjectList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS), constraints);
// So wird sie richtig angezeigt, das bring mit aber nichts weil ich sie ja gerne scrollen würde...
gbl.addLayoutComponent(this.uiOceanObjectList, constraints);
splitPane.setRightComponent(controlPanel);
// Insert the split pane.
this.add(splitPane, BorderLayout.CENTER);
}
Die besagte Liste ist this.uiOceanObjectList.