【问题标题】:Example Program JMenubar on JInternalFrame when i Maximize the JInternalFrame当我最大化 JInternalFrame 时 JInternalFrame 上的示例程序 JMenubar
【发布时间】:2012-11-30 19:41:30
【问题描述】:

您好,我需要一个示例程序,其中 当我最大化 JInternalFrame 时,JFrame 的 JMenuBar 应该设置在 JInternalFrame 上 当我再次最小化 JInternalFrame 时,JMenuBar 应该离开 JinternalFrame 并设置 到JFrame如下图

请提供一个 Java Swing 示例程序

【问题讨论】:

  • 请提供解决方案

标签: java swing jinternalframe jmenubar


【解决方案1】:

似乎工作正常,请发帖SSCCE 以显示具体问题:

import java.awt.*;
import java.awt.event.*;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

public class JInternalFrameDemo {

    JDesktopPane jdpDesktop;
    static int openFrameCount = 0;

    public JInternalFrameDemo() {
        JFrame frame = new JFrame("JInternalFrame Usage Demo");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // A specialized layered pane to be used with JInternalFrames
        jdpDesktop = new JDesktopPane() {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(600, 600);
            }
        };


        createFrame(); // Create first window

        frame.setContentPane(jdpDesktop);

        frame.setJMenuBar(createMenuBar());

        // Make dragging faster by setting drag mode to Outline
        jdpDesktop.putClientProperty("JDesktopPane.dragMode", "outline");

        frame.pack();
        frame.setVisible(true);
    }

    protected JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("Frame");
        menu.setMnemonic(KeyEvent.VK_N);
        JMenuItem menuItem = new JMenuItem("New IFrame");
        menuItem.setMnemonic(KeyEvent.VK_N);
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                createFrame();
            }
        });
        menu.add(menuItem);
        menuBar.add(menu);
        return menuBar;
    }

    protected void createFrame() {
        MyInternalFrame frame = new MyInternalFrame();
        frame.setVisible(true);
        // Every JInternalFrame must be added to content pane using JDesktopPane
        jdpDesktop.add(frame);
        try {
            frame.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JInternalFrameDemo();
            }
        });
    }

    class MyInternalFrame extends JInternalFrame {

        static final int xPosition = 30, yPosition = 30;

        public MyInternalFrame() {
            super("IFrame #" + (++openFrameCount), true, // resizable
                    true, // closable
                    true, // maximizable
                    true);// iconifiable
            setSize(300, 300);
            // Set the window's location.
            setLocation(xPosition * openFrameCount, yPosition
                    * openFrameCount);
        }
    }
}

【讨论】:

  • 先生,我已经尝试过上面的代码,但是当我最大化 JInternalFrame 时,它​​没有捕获 JMenuBar,所以我可以在上面的代码中尝试任何解决方案
  • @ZaheerBoovaji 请查看并尝试更新的代码...它对您有用吗?您一定不要忘记添加JDesktopPane 并将其设置为您的contentPane,所有内容都将添加到desktopPane
  • 先生,我已经尝试了更新的代码我想要的是当我最大化 JInternalFrame 时,JMenuBar 应该设置在 JinternalFrame 而不是 JFrame 上
  • @ZaheerBoovaji 不应该这样做违反了国际海事组织的公约。因此,为什么JDesktopPane 会为我们整理出JMenuBar
  • @ZaheerBoovaji:一段时间后,您可以通过点击左侧的empty check mark 来接受这个答案。
【解决方案2】:

我也有类似的问题。这是 JInternalFrame LookAndFell 中的一个错误。 JInternalFrames 使用 Windows L&F,应该是 更喜欢Windows。如果我最大化 JInternalWindow, 该窗口不像在 Windows 中那样工作。 它的顶栏应与 MDI 为一。 Meus 和工具栏应该在里面。 最大化的内部框架不应该有它们的 自己的边界。

访问 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4102061 用于数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 2011-07-02
    • 2020-04-01
    相关资源
    最近更新 更多