Set JLabel Size to FlowLayout

I have a JPanel that uses FlowLayout. I am adding several JLabels to a JPanel, use setPreferedSize () to adjust their size and save them in the label_list. Everything is working fine. Then I want to resize them:

for(JLabel c:label_list){
c.setPreferedSize(new Dimension(10,10));
}

And it does not work.

c.setBackground(Color.red)

and similar things work. Why can't I use setPreferedSize here?

c.setBounds (1,1,10,10) and c.setSize (10,10) Works, but after updating the user interface (resizing the panel), each size returns to its normal state.

+5
source share
1 answer

Then I want to resize them:

for (JLabel c: label_list) {c.setPreferedSize (new dimension (10,10)); }

And it does not work.

revalidate() , .

c.setBounds(1,1,10,10) c.setSize(10,10) , UI ( ), .

// LayoutManager . LayoutManager .

null, setSize-setLocation/setBounds LayoutManager () setSize-setLocation/setBounds. setPreferred/setMaximum/setMinimum size, , L & F.

+5

All Articles