2

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:

enter image description here

This one works just fine:

enter image description here

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:

enter image description here

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

  1. Needs to have a combobox at the bottom of the application, such that the menu goes outside the window.
  2. 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

  1. Theme doesn't matter, so if you run it with "Windows" or "Nimbus", the bug still persists.
  2. Parents don't matter, It can still happen by calling it directly or calling it from another jframe.
  3. It happens on jdialog as well.
  4. [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                   
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Eds
  • 380
  • 1
  • 13
  • Works fine for me on Windows 10 using JDK 11. Note: your GUI components are NOT being created on the EDT. For some reason you (Netbeans) only invokes the setVisible() statement on the EDT. I have always created all Swing components and changed the LAF on the EDT as the Swing tutorials recommend. – camickr Nov 06 '20 at 02:21
  • Forgot to mention I am using JDK 15. Just updated the code back (Runnable inside event queue) to what it originally was when NetBeans generated. That should be running on EDT I think. The bug is still happening for me though. – Eds Nov 06 '20 at 05:52
  • *That should be running on EDT I think* No that is not what I was referring to. In the examples from the [Swing Tutorial](https://docs.oracle.com/javase/tutorial/uiswing/TOC.html), all the main() method does is create the Runanable to be executed on the EDT. Read the section from the tutorial on `Concurrency in Swing` for more information. Then check out the `FrameDemo` code found in the section on `How to Make Frames` for the implementation of my suggest. Note this is unlikely to fix the problem, I'm just saying there is the potential for random problems when you don't follow this advice. – camickr Nov 06 '20 at 15:22

0 Answers0