首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >全屏JFrame之上的模态JFrame

全屏JFrame之上的模态JFrame
EN

Stack Overflow用户
提问于 2012-12-26 02:26:45
回答 1查看 567关注 0票数 0
代码语言:javascript
复制
package javaapplication1;

import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        final JFrame frame = new JFrame();
        final NewJPanel p = new NewJPanel();
        frame.setTitle("Frame");
        frame.setSize(300, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        device.setFullScreenWindow(frame);
        device.setDisplayMode(new DisplayMode(800, 600, 32, 60));


        JButton btn = new JButton();
        btn.setText("Button");
        JPanel panel = new JPanel();

        panel.add(btn);
        frame.add(panel);

        btn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JFrame f = new JFrame();
                JPanel p = new JPanel();
                f.setSize(300, 300);
                p.setBackground(Color.red);

                f.add(p);
                f.setLocationRelativeTo(null);
                f.setAlwaysOnTop(true);
                f.setVisible(true);
            }
        });
    }
}

我想在全屏的JFrame中弹出f.setVisible(true);,当我点击按钮时,它被设置为模式。我该怎么做呢?因为在该代码中,当我单击按钮时,f.setVisible(true);会显示在全屏JFrame之外。期待你的回答。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-26 02:56:05

因此,您希望在主JFrame中包含类似于JInternalFrame的内容

代码语言:javascript
复制
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class JavaApplication1 {

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                final JFrame frame = new JFrame();
                final JDesktopPane desktopPane = new JDesktopPane();
                frame.setTitle("Frame");
                frame.setSize(300, 300);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                final GraphicsDevice device = GraphicsEnvironment
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice();
                device.setFullScreenWindow(frame);
                device.setDisplayMode(new DisplayMode(800, 600, 32, 60));

                JButton btn = new JButton();
                btn.setText("Button");
                JPanel panel = new JPanel();

                panel.add(btn);
                frame.add(panel, BorderLayout.NORTH);
                frame.add(desktopPane, BorderLayout.CENTER);

                btn.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JInternalFrame f = new JInternalFrame();
                        JPanel p = new JPanel();
                        p.setBackground(Color.red);
                        f.setSize(300, 300);
                        f.setResizable(true);
                        f.add(p);
                        f.setVisible(true);
                        desktopPane.add(f);
                    }
                });
            }
        });

    }
}

有关JInternalFrame的更多信息,请访问here

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

https://stackoverflow.com/questions/14033033

复制
相关文章

相似问题

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