I want to place 10 JPanels in a circle. Each panel is the same size, and the length between the two panels must be the same. Thus, the easiest way is to capture the null layout and calculate the bounding box manually through the coordinate fields:
JPanel panel = new JPanel(null);
int r = 100;
int phi = 90;
for (int i = 0; i < 10; i++) {
JPanel x = new JPanel();
x.setBackground(Color.red);
x.setBounds((int) (r * Math.sin(phi)) + 100, (int) (r * Math.cos(phi)) + 100, 4, 4);
panel.add(x);
phi = (phi + 36) % 360;
}
But it does not work! Some objects are in a circle, some of them are pixels ... I have no idea why ?! I also cannot find a LayoutManager that can do this for me, and what should I do?
source
share