最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to get the swing component to render upon the AWT component. (Splitpane divider on AWT panel) - Stack Overflow

programmeradmin3浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论