Questions about using namedWindow() and imshow() in Java

How can I modify my Java code using the namedWindow() and imshow() functions to open and display two windows simultaneously? Currently, when I run the code, it opens and closes a window repeatedly instead of keeping both windows open at the same time.

public static void main(String[] args) {
        System.load("opencv_java481.dll");

        Mat img = Imgcodecs.imread("path-to-an-image", Imgcodecs.IMREAD_COLOR);
        namedWindow("Display window1", HighGui.WINDOW_NORMAL);
        HighGui.imshow("Display window1", img);
        namedWindow("Display window2", HighGui.WINDOW_NORMAL);
        HighGui.imshow("Display window2", img);

        while (true) {
            HighGui.imshow("Display window1", img);
            waitKey(10);

            HighGui.imshow("Display window2", img);
            waitKey(10);
        }
    }

I believe my code is correct, and I have tested it with a Python code that has a similar function (in my opinion), and it successfully opens two windows simultaneously without closing them.

    img = cv2.imread(r"path-to-an-image", cv2.IMREAD_COLOR)

    cv2.namedWindow("Display window 1", cv2.WINDOW_NORMAL)
    cv2.namedWindow("Display window 2", cv2.WINDOW_NORMAL)

    while True:
        cv2.imshow("Display window 1", img)
        cv2.waitKey(10)
        
        cv2.imshow("Display window 2", img)
        cv2.waitKey(10)

I am currently running my code on Windows 11, using OpenCV version 4.8.1. How can I resolve the issue I am facing with the code?

something else must be interfering with the GUI. any competing GUI libraries in the mix?

your window names differ in capitalization. you should fix that. with that java code, you should be getting four different windows.

and please don’t slap random tags on your question. I’ve cleaned that up.

something else must be interfering with the GUI. any competing GUI libraries in the mix?

I am not using any other GUI libraries in my code. I downloaded the prebuilt files of OpenCV from SourceForge and I am not aware of which GUI libraries it depends on or how to specifically select its highgui libraries without built from opencv source files.

Is it possible that the issue is caused by the prebuilt OpenCV files relying on incorrect backend GUI modules? If so, where can I find alternative prebuilt files that use different backend GUI modules? Alternatively, do I need to build OpenCV from source files to resolve this problem?

your window names differ in capitalization. you should fix that. with that java code, you should be getting four different windows.

I have corrected this in my question. However, even after making this correction, the issue of the windows repeatedly opening and closing persists.

please don’t slap random tags on your question. I’ve cleaned that up.

Thanks, It’s my first time asking question on this forum. I’ll pay attention next time.

please be aware, that the gui used with the java wrappers is a java ‘mockup’ of the usual highgui functionality.
it is swing - based, and not using any other c++ based dependancies (like qt or gtk)

Is there a way to solve the problem I encountered? Or is it a bug in the code that needs to be addressed?