Я пытался отобразить объект построчно, где каждая строка - это объект. Затем я использую макет коробки, но когда я это делаю, рисуется только верхний слой (который является последним вызываемым объектом), как я могу это нарисовать?
вот минимальный пример:
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
MainFrame frame = new MainFrame();
}
}
private class MainFrame extends JFrame {
public MainFrame(){
setSize(600,400);
setLocationRelativeTo(null);
setVisible(true);
setContentPane(new Container());
}
}
private class Container extends JPanel {
public Container(){
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
for(int i =0;i<10;i++){
add(new Line());
}
}
}
private class Line extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.green);
g.fillRect(getX(),getY(),getWidth(),getHeight());
}
}
вот что у меня:

and what I've expected :

Some test (the blue rectangle in the paint method of the JBackPannel class) showed me that somewhere something is drawing a white canvas, but I don't know where and why ...
here is a link to a минимальный пример