Πέμπτη 21 Απριλίου 2022

Ubuntu javajdk bug JTabbedPane JScrollPane

This bug is not a bug if i am running in windows 7...
It is a bug and application crashes in Ubuntu 20.04 LTS
ANd until i can find a way to report this
either on java or oracle either on ubuntu....
i am making this post.

The problem is that
if we add a javax.swing.JScrollPane
to a javax.swing.JTabbedPane that is NOT VISIBLE
then the application crashes....in Ubuntu 20.04 LTS(not in windows)

But if we add some other component like javax.swing.JTextArea
to a javax.swing.JTabbedPane that is NOT VISIBLE
then is ok.....


But is all ok if the JTabbedPane is Visible (via its frame)
when we add any Component either JScrollPane

So in below code

"play" with the following line to see the bug.....
//UNCOMMENT FOLLOWING  methodStyle=true to run ok

I have just added a little code with JOptionPane to be able to check it
in many OS (windows 7,ubuntu,win 10..etc)

If you dont want to check the code your self then just download this
and if in ubuntu ..properties->permissions->allow executing file as program

https://drive.google.com/file/d/1faR_76E5EjaTDE0bpqT569e2AgsDn9fc/view?usp=sharing

I thing that the method JTabbedPane.addTab(String,Component)
is not provoking the problem(in ubuntu jdk)
but the validate() method is crashing......(of the Frame)



--------------------------------------------------------------

 
package ubuntujdkbugs;

import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

public class UbuntuCrashWhenAddJScrollPaneToJTabbedPaneNotBeingVisible {

    public static void main(String[] args) {
        // TODO code application logic here
        JFrame jfr=new JFrame("Ubuntu bug tester JTabbedPane-JScrollPane");
        jfr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jfr.setBounds(111,111,333,333);
        
        /**
         * If this command (jfr.setVisible(true);)
         * is BEFORE we add to JTabbedPane DIRECTLY a JScrollpane
         * then all working fine
         * So i have commented to see what is happening
         * if we call JTabbedPane.addTab("",someJScrollPane)
         * BEFORE this JTAbbepPane is visible
         *
         * But all those are running OK in windows 7
         * Just in Ubuntu i have the problem
         */
        //jfr.setVisible(true);//uncomment this and use below false->run and true->run to see its ok in both cases
        
        JTabbedPane jtp=new JTabbedPane();
        jfr.getContentPane().add(jtp);
        //jfr.validate();//no need for this ...may
        
        System.out.println("adding the JScrollPane");
        boolean methodStyle=true;
        int answer=JOptionPane.showConfirmDialog(null,"Would you like to see the bug ?"
                + "\nby crashing jdk of Ubuntu 20.04 LTS ...?"
                + "\n\nYou must see a JFrame after this..."
                + "\nIf not see then app is crashed ."
                + "\n Press NO to see the NOT CRASHED APPLICATION"
                + "\nPress YES (just enter) and do this "
                + "once in windows and once in ubuntu 20.04 LTS"
                + "\n\n\nYES will add a JScrollPane directly to JTabbedPane with jtp.addTab(\"\",somScrollPane)"
                + "\nNO will add this JScrollPane NOT DIRECTLY but via a new JPanel that has child the JScrollPane"
                ,"mes:Enter or press No",JOptionPane.YES_NO_OPTION);
        
        methodStyle = answer != JOptionPane.YES_OPTION;

        //methodStyle=false;//UN-COMMENT THIS IN UBUNTU AND YOU GET A CRASH
        addScrollableComponent(methodStyle,jtp, new JTextArea("ok"));
        //jtp.addTab("*",new JTextArea("single area"));
        System.out.println("JScrollPane added ok!");
        
        jfr.setVisible(true);
        System.out.println("JFrame is Visible ok");
        
    }
    static void addScrollableComponent(boolean createJPanelSTyle,JTabbedPane jtp,Component c){
        JScrollPane jscr=new JScrollPane(c);
        Component compToAdd=jscr;
        if(createJPanelSTyle){
            JPanel jp=new JPanel(new BorderLayout());
            jp.add(BorderLayout.CENTER,jscr);
            compToAdd=jp;
        }
        
        
        jtp.addTab("*",compToAdd);
        //jtp.validate();
    }

    
}

Δεν υπάρχουν σχόλια: