1
I have little experience with Java Swing and am getting beat up with one simple thing.
The code below produces glitches (artifacts/dirt) on the screen when the scroll bar is dragged repeatedly and I don’t know why (maximize the screen first to see better and drag up and down the scroll bar).
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();
}
});
}
}
Screen with glitches:
Here did not give any problem when executing.
– user28595
Sometimes it takes time to happen. You have to drag up and down several times. But it may also be that the problem just happens to me.
– Piovezan
I did it until my arm hurt :p and nothing happened
– user28595
Until the arm hurts is good :D right, I’ll investigate on my side then.
– Piovezan
It may be due to windows aero. I noticed that you are running under a windows 7 with aero active, and my windows is 7 too, but aero is disabled
– user28595
From the code, it seems to have been generated by netbeans, does this problem occur when you run inside netbeans? You tried to run the part outside the IDE?
– user28595
I did the test here, both compiling the jar and running by eclipse and it didn’t happen. The OS I use here is linux and I am with version 8 of java.
– Adriano Gomes
Look, and it’s not that disabling the Aero solved?
– Piovezan
Problem solved. Guilty: Microsoft :p
– user28595
To disable Aero right-click on the desktop and choose Customize, then select another theme, for example Basic.
– Piovezan