首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在JInternalFrame上最大化JInternalFrame时的示例程序JMenubar

在JInternalFrame上最大化JInternalFrame时的示例程序JMenubar
EN

Stack Overflow用户
提问于 2012-12-01 03:41:30
回答 2查看 8.9K关注 0票数 4

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

请给我提供一个Java Swing的示例程序

EN

回答 2

Stack Overflow用户

发布于 2012-12-01 03:49:11

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

代码语言:javascript
运行
复制
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);
        }
    }
}
票数 6
EN

Stack Overflow用户

发布于 2013-04-07 14:30:32

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

有关数据,请访问http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4102061

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13651991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档