I am not sure if this is only happening on my machine or what, but the bug seems interesting so I am posting it on here to see if anyone has encountered it. It will be nice if anyone is up for finding out why or testing it out as well.
Btw, similar issue here. It might be the same bug, not too sure. Though that one seems like happening on Nvidia, I am using AMD. (It will be quite funny though if it is the same bug, still exist after 6 years.)
Note that I am using JDK 15.0.1.
Bug Explained
A simple Swing application I created in NetBeans:
This one works just fine:
Rendering bug after clicking the bottom combobox. Then the bug just stuck wherever the cursor is because it causes a repaint. It can be fixed if I resize, minimize or moved the window below taskbar and backed up:
However, if this window is closed with the bug not fixed, the bug stays forever on other opened window within the same application and cannot be fixed. (At least from what I tried).
Encountered this bug when building my own application. Got some spare time so I spent some time seeing what triggers it.
Trigger Condition
- Needs to have a combobox at the bottom of the application, such that the menu goes outside the window.
- Needs to have a textArea present in the window. The bug disappears after I removed the textArea. (It might need to be on the side like in the example. Haven't tested if the layout of it matters or not). (It might also to do with scrollPane, haven't tested it as well.)
What I have tested
- Theme doesn't matter, so if you run it with "Windows" or "Nimbus", the bug still persists.
- Parents don't matter, It can still happen by calling it directly or calling it from another jframe.
- It happens on jdialog as well.
- [Edit] Tested with and without runnable, Eventqueue.
Code
You can copy and paste the code below or just download and run the project on NetBeans. (I am using ver 12.1): https://drive.google.com/file/d/1PyrQ4IVYe5xDfXiXSip0rifxPbatKKcT/view
package javaapplication1;
public class JavaApplication1 {
public static void main(String[] args){
try
{
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
{
if ("Windows".equals(info.getName()))
{
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
}
catch (ClassNotFoundException ex) {java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);}
catch (InstantiationException ex) {java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);}
catch (IllegalAccessException ex) {java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);}
catch (javax.swing.UnsupportedLookAndFeelException ex) {java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);}
NewJFrame frame = new NewJFrame();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
}
package javaapplication1;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel8 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 300));
jButton2 = new javax.swing.JButton();
filler20 = new javax.swing.Box.Filler(new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 300));
jComboBox2 = new javax.swing.JComboBox<>();
filler5 = new javax.swing.Box.Filler(new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 300));
filler4 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767));
jPanel1 = new javax.swing.JPanel();
filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 300));
jButton1 = new javax.swing.JButton();
filler19 = new javax.swing.Box.Filler(new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 300));
jComboBox1 = new javax.swing.JComboBox<>();
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 0), new java.awt.Dimension(50, 300));
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Test");
setPreferredSize(new java.awt.Dimension(550, 400));
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));
jPanel8.setLayout(new javax.swing.BoxLayout(jPanel8, javax.swing.BoxLayout.X_AXIS));
jPanel7.setLayout(new javax.swing.BoxLayout(jPanel7, javax.swing.BoxLayout.Y_AXIS));
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.X_AXIS));
jPanel2.add(filler3);
jButton2.setText("jButton1");
jButton2.setAlignmentX(0.5F);
jPanel2.add(jButton2);
jPanel2.add(filler20);
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7" }));
jComboBox2.setMaximumSize(new java.awt.Dimension(32767, 20));
jPanel2.add(jComboBox2);
jPanel2.add(filler5);
jPanel7.add(jPanel2);
jPanel7.add(filler4);
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.X_AXIS));
jPanel1.add(filler2);
jButton1.setText("jButton1");
jPanel1.add(jButton1);
jPanel1.add(filler19);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7" }));
jComboBox1.setMaximumSize(new java.awt.Dimension(32767, 20));
jPanel1.add(jComboBox1);
jPanel1.add(filler1);
jPanel7.add(jPanel1);
jPanel8.add(jPanel7);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jPanel8.add(jScrollPane1);
getContentPane().add(jPanel8);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.Box.Filler filler1;
private javax.swing.Box.Filler filler19;
private javax.swing.Box.Filler filler2;
private javax.swing.Box.Filler filler20;
private javax.swing.Box.Filler filler3;
private javax.swing.Box.Filler filler4;
private javax.swing.Box.Filler filler5;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JComboBox<String> jComboBox2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}