I am trying to vertically align (center) both JLabels inside one JPanel.
JPanel panel = new JPanel();
panel.setPreferredSize(size);
JLabel label1 = new JLabel(icon);
JLabel label2 = new JLabel("text");
panel.add(label1);
panel.add(label2);
I have tried using setAligmentY() with no success. Both labels always appear on the top of JPanel.
UPD: Labels should be located next to each other like using FlowLayout, but in the middle of the JPanel.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…