#JPanel not showing up.

8 messages · Page 1 of 1 (latest)

heavy frigate
#
    void drawOtherPanel() {
        System.out.println("TEST PRINT"); // this gets printed
        
        removePanels();
        
        mainPanel.add(otherPanel);
        
        validate();
        repaint();
    }

I'm working with some swing graphics code. I have this method which is supposed to draw a certain panel when a button is clicked, but it does nothing. Why does it not work?

dark basaltBOT
#

This post has been reserved for your question.

Hey @heavy frigate! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fathom tundra
#

what does the removePanels() do?

#

you must set the layout properly too

heavy frigate
#

It removes all the other panels from mainPanel.

fathom tundra
#

set a layout before adding them to the mainPanel

heavy frigate
#

I used absolute layout for otherPanel.