I have little experience with Java Swing and am catching up with a simple thing.
The code below produces glitches on the screen when the scroll bar is dragged repeatedly and I do not know why (maximize the screen first to see better and drag the scroll bar up and down).
The example is minimal, complete, and verifiable.
import java.awt.EventQueue;
import java.awt.Font;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class GroupPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JPanel jPanelListaOrders = new JPanel();
private JScrollPane jScrollPaneOrders = new JScrollPane(jPanelListaOrders);
public GroupPanel() {
javax.swing.GroupLayout jPanelMainLayout = new javax.swing.GroupLayout(this);
jPanelMainLayout.setHorizontalGroup(jPanelMainLayout.createParallelGroup(Alignment.LEADING)
.addGroup(jPanelMainLayout.createSequentialGroup()
.addGroup(jPanelMainLayout.createParallelGroup(Alignment.LEADING)
.addComponent(jScrollPaneOrders))
));
jPanelMainLayout.setVerticalGroup(jPanelMainLayout.createParallelGroup(Alignment.LEADING)
.addGroup(jPanelMainLayout.createSequentialGroup().addGroup(
jPanelMainLayout.createParallelGroup(Alignment.LEADING)
.addGroup(jPanelMainLayout.createSequentialGroup()
.addComponent(jScrollPaneOrders)))));
this.setLayout(jPanelMainLayout);
jPanelListaOrders.setBackground(new java.awt.Color(254, 254, 254));
jPanelListaOrders.setLayout(new javax.swing.BoxLayout(jPanelListaOrders, javax.swing.BoxLayout.Y_AXIS));
for (int i = 1; i <= 20; i++) {
JLabel label = new JLabel("Exemplo " + i);
label.setFont(new Font("Tahoma", Font.BOLD, 60));
jPanelListaOrders.add(label);
}
revalidate();
repaint();
}
private static void display() {
JFrame f = new JFrame("GroupPanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
f.add(new GroupPanel());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
display();
}
});
}
}
Glitches screen: