Hey,
ich habe in meinem Programm eine JScollPane eingebaut. Diese ist in der "Haupt-GUI"-Klasse und auch in meinem JFrame sichtbar.: *Mit rot umkreist.
Nun hab ich eine Methode in der "Haupt-GUI"-Klasse, in der die ganzen Komponenten dem Frames hinzugefügt werden. :
(JPanelOverlay ist eine Klasse, die von JPanel ableitet und als Panel für das gesamte Frame genutzt wird.)
Diese Methode wird im GUI-Konstruktor aufgerufen.
Nun hab ich noch eine Klasse, die für den Inhalt des ScollPanes sorgt. Allerdings erscheint nichts im ScollPane:
Diese Methode wird im Konstruktor ihrer eigenen Klasse aufgerufen.
Der Konstruktor dieser Klasse wird in der "Haupt-GUI"-Klasse aufgerufen, und zwar vor der Methode
Ich finde leider nicht den Auslöser des Problems. Es ist übrigens das erste mal, das ich mit einem Scollpane arbeite. Vielleicht füeg ich das Panel den ScollPane auch einfach falsch hinzu, aber ich glaube, dass in der Shop-Klasse das Problem liegt.
Ich hoffe mir kann jemand helfen.
Vielen Dank
ich habe in meinem Programm eine JScollPane eingebaut. Diese ist in der "Haupt-GUI"-Klasse und auch in meinem JFrame sichtbar.: *Mit rot umkreist.
Nun hab ich eine Methode in der "Haupt-GUI"-Klasse, in der die ganzen Komponenten dem Frames hinzugefügt werden. :
Code:
public void addComponetsToPanelOverlay() {
this.panelOverlay.setLayout(null);
this.lblCookie.setBounds(119, 201, 210, 210);
this.panelOverlay.add(this.lblCookie);
this.lblCookieClicked.setBounds(119, 201, 210, 210);
this.lblCookieClicked.setVisible(false);
this.panelOverlay.add(this.lblCookieClicked);
this.lblCookiesProKlick.setBounds(28, 27, 179, 35);
this.lblCookiesProKlick.setFont(fontCookies);
this.lblCookiesProKlick.setForeground(Color.LIGHT_GRAY);
this.panelOverlay.add(this.lblCookiesProKlick);
this.lblAnzahlCookies.setBounds(217, 27, 220, 35);
this.lblAnzahlCookies.setFont(this.fontCookies);
this.lblAnzahlCookies.setForeground(Color.LIGHT_GRAY);
this.panelOverlay.add(this.lblAnzahlCookies);
this.lblCookieShop.setBounds(504, 30, 230, 40);
this.lblCookieShop.setFont(fontCookieShop);
this.lblCookieShop.setForeground(Color.WHITE);
this.panelOverlay.add(this.lblCookieShop);
this.lblShop.setBounds(464, 81, 148, 40);
this.lblShop.setOpaque(true);
this.lblShop.setBorder(new BevelBorder(BevelBorder.LOWERED, new Color(0, 0, 51), null, null, null));
this.lblShop.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 23));
this.lblShop.setBackground(new Color(0, 0, 153));
this.lblShop.setForeground(new Color(255, 255, 255));
this.panelOverlay.add(this.lblShop);
this.lblAchievements.setBounds(610, 81, 154, 40);
this.lblAchievements.setOpaque(true);
this.lblAchievements.setBorder(new BevelBorder(BevelBorder.LOWERED, new Color(0, 0, 51), null, null, null));
this.lblAchievements.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 23));
this.lblAchievements.setBackground(new Color(0, 0, 153));
this.lblAchievements.setForeground(new Color(255, 255, 255));
this.panelOverlay.add(this.lblAchievements);
this.panelAchievements.setLayout(new BoxLayout(this.panelAchievements, BoxLayout.Y_AXIS));
this.scrollPaneShop.setBounds(464, 121, 300, 302);
this.scrollPaneShop.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
this.scrollPaneShop.add(cookieShop.getPanelShop());
this.panelOverlay.add(this.scrollPaneShop);
this.scrollPaneAchievements.setBounds(464, 121, 300, 302);
this.scrollPaneAchievements.setVisible(false);
this.scrollPaneAchievements.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
this.scrollPaneAchievements.add(this.panelAchievements);
this.panelOverlay.add(this.scrollPaneAchievements);
this.getContentPane().add(this.panelOverlay);
}
Diese Methode wird im GUI-Konstruktor aufgerufen.
Nun hab ich noch eine Klasse, die für den Inhalt des ScollPanes sorgt. Allerdings erscheint nichts im ScollPane:
Java:
public class CookieShop {
private JPanel panelShop;
private JPanelOverlay panelShopCursor;
private JPanelOverlay panelShopSupp;
private JLabel lblShopCursor;
private JLabel lblShopSupp;
private List<JPanelOverlay> shopPlates = new ArrayList<JPanelOverlay>();
public CookieShop() {
this.initialComponents();
this.registerShopComponentsInList();
}
public void initialComponents() {
this.panelShop = new JPanel();
this.panelShopCursor = new JPanelOverlay("images/ShopCursorPlate.png");
this.panelShopSupp = new JPanelOverlay("images/ShopSuppPlate.png");
this.lblShopCursor = new JLabel("Preis");
this.lblShopSupp = new JLabel("Preis");
}
public void registerShopComponentsInList() {
//panelShopCursor
this.panelShopCursor.setPreferredSize(new Dimension(300, 125));
this.panelShopCursor.setLayout(new BorderLayout());
this.panelShopCursor.add(new JLabel("Cursor"), BorderLayout.NORTH);
this.panelShopCursor.add(this.lblShopCursor, BorderLayout.CENTER);
//panelShopSupp
this.panelShopSupp.setPreferredSize(new Dimension(300, 125));
this.panelShopSupp.setLayout(new BorderLayout());
this.panelShopSupp.add(new JLabel("Supp"), BorderLayout.NORTH);
this.panelShopSupp.add(this.lblShopSupp, BorderLayout.CENTER);
this.panelShop.setLayout(new BoxLayout(this.panelShop, BoxLayout.Y_AXIS));
shopPlates.add(this.panelShopCursor);
shopPlates.add(this.panelShopSupp);
for(JPanelOverlay shopPlate : shopPlates) {
this.panelShop.add(shopPlate);
}
//hier noch Getter & Setter dazudenken
}
Der Konstruktor dieser Klasse wird in der "Haupt-GUI"-Klasse aufgerufen, und zwar vor der Methode
Java:
this.addComponetsToPanelOverlay();
Ich hoffe mir kann jemand helfen.
Vielen Dank