简体   繁体   中英

Reparent and insert a X-Window into the Java component tree

I have to reparent a X-Window (from a C++ app) on a Java frame (from a java app). This X-Window has to be inserted inside the Java component tree so that the z-Order would be respect. To do that, I need to understand:

  1. First, the exact relationship between the component tree created by a Java application and the matching X-Window tree.
  2. Second, whether and where I can insert a X-Window on the Java tree thanks to the reparent.
  3. Third, the way the window/component stack is handled: which window/component would be on top of another.

Several weeks of research... but I don't find any resource on these questions...

About the question 1 . As far I understand, If i create a java main frame with components and two other frames the Swing tree should looks like this:

                                Frame0
                                   :
                                   :-------------------------------
                                   :               :              :
                               Component         Frame1         Frame2
                                   :
                     Component-----------Component

About the X-Window tree: aach Frame is an Heavy-Weight component, so each Frame has a X-Window ID. So the X-Window tree could look like this:

                                Frame0
                                   :
                         Frame1---------Frame2

About the question 2 . My question is: what happens if I insert an Applet (so an Heavy-Weight component) in the middle of the Swing tree among other components? What the X-window would look like? I hope that by this way I can reparent a X-Window on a Java Application and that this X-Window would be inserted in the Java tree.

About the question 3 . Even if I can reparent/insert the X-Window into the Java Application, I'm not sure that the z-order would be respected. In fact, I made a trial and the X-Window has appeared on top of all the component of the Java Frame. I'm not sure to understand the way the window/component stack is handled and its relationships with the java and the X-Window trees.

Honest disclosure - it has been at least twelve years since I did this type of thing. So take this as "for what it is worth."

First, every Swing object in the tree has a heavy-weight container higher up in the Swing component tree - even if it is just the outermost frame. The Swing objects are just logical drawing regions on that XWindow's surface.

Question 1: Your answer in the first case is correct provided Frame1 and Frame2 are embedded inside Frame0. Otherwise they are independent XWindows.

Question 2: When you insert a new heavy weight component in the Swing tree, your new component will be added as a new XWindow component child of the XWindow containing the drawing surface of the Swing component it is added to. This is the part of the answer my memory is most fuzzy on.

Question 3: (the meat of the matter). The XWindow system first decides which XWindow windows are visible at each point. Then, within each XWindow, but not across XWindows, Swing the draws the corresponding Swing subtree in that region. More accurately, Java draws the Swing sub-tree for each heavy-weight component on the matching XWindow canvas. The XWindow server then determines which portion of these canvases is visible at each point based solely on the XWindow tree.

So, if you have some Swing object in Frame0 that is closer to the viewer than anything in Frame1 using z-order but it is overlapped by Frame1, IT DOESN'T MATTER. The XWindow ordering will win and Swing components from Frame1 will be drawn.

Note - once you understand this you can use it to provide "hard" clipping of Swing objects.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM