I have a SplitPane, where the right component is a tabbed pane, and each tab is a JInternalFrame. This JInternalFrame holds the AWT Panel (this panel is needed for my application to communicate other JNI calls using a native handle). I have a continuous layout set to false in Splitpane UI. Now, when I slide the split pane divider, it goes behind the AWT panel. How to fix this z-order issue.
Please refer the following image that I have attached. enter image description here
Now I am attaching the code.
import javax.swing.*;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;
public class SplitPaneExample {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("SplitPane Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
// Create left component
JPanel leftPanel = new JPanel();
leftPanel.add(new JLabel("Left Component"));
// Create right component
JTabbedPane tabbedPane = new JTabbedPane();
JInternalFrame internalFrame = new JInternalFrame("Internal Frame", true, true, true, true);
internalFrame.setSize(400, 300);
internalFrame.setVisible(true);
// Create a layered pane to manage z-order
// Create the AWT Panel
Panel awtPanel = new Panel();
awtPanel.setBackground(Color.CYAN);
awtPanel.add(new Label("AWT Panel inside JInternalFrame"));
// Add AWT Panel to internal frame
internalFrame.add(awtPanel);
internalFrame.pack();
internalFrame.setVisible(true);
// Add internal frame to tabbed pane
tabbedPane.addTab("Tab 1", internalFrame);
// Create SplitPane
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, tabbedPane);
splitPane.setDividerLocation(200);
// Add splitPane to layeredPane
frame.add(splitPane);
frame.setVisible(true);
});
}
}
I have tried using JLayeredPane to hold the splitpane/ tabbedpane/ Awt panel... but nothing worked.
Any suggestions or workaround is highly appreciated. Any suggestions on alternate way to get handle for JNI in this hierarchy is also highly appreciated.