Answer the question
In order to leave comments, you need to log in
Java, Swing. Why don't other components appear?
When I add a lot of elements in a loop, only a certain number of the first ones are displayed, the rest are simply ignored, and the number of drawn ones is different with each compilation. Why is this happening? How to fight?
public GUI(String windowName, ArrayList<String> pupilList) { //конструктор класса унаследованного от JFrame
super(windowName);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(640, 480);
setResizable(false);
setLocationRelativeTo(null);
setLayout(null);
this.pupilList = new ArrayList<>();
for (int i = 0; i < pupilList.size(); i++) {
this.pupilList.add(new JLabel(pupilList.get(i)));
this.pupilList.get(i).setBounds(10, 10 + 20*i, 200, 15);
add(this.pupilList.get(i));
}
...
}
Answer the question
In order to leave comments, you need to log in
setVisible(true);
Rearrange as far as possible, preferably at the very end. Components may not have time to render. I remember this often happened when I wrote on the swing, and also a different number of components were drawn at each launch. Or try updating/redrawing the window. But there, using tricky methods, you need to redraw it, unfortunately I don’t remember, perhaps frame.update (...) is even enough.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question