H
H
hHup2018-04-04 22:52:37
Java
hHup, 2018-04-04 22:52:37

How to clear a JPanel?

JPanel panel=new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new JButton("1"));
panel.add(new JButton("2"));

We created the panel, set the layout, added 2 buttons. Is there a command to quickly clear the entire panel, if so, will the layout rules be removed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
P_Alexander, 2018-04-05
@TopMetaFizick

JPanal.removeAll();

M
MaxLich, 2018-04-05
@MaxLich

Try calling the removeAllItems() method first, and then repaint() and revalidate(). As far as I remember, this is how it worked for me (exactly these three methods, and in that order).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question