全屏模式下的 JInternalFrame

发布于 2024-11-09 13:28:39 字数 212 浏览 0 评论 0原文

我打算在全屏模式下使用 JInternalFrame 作为模态 JDialog,但是,当前在调用它时并未显示它。我需要将其添加到某个容器中吗?我尝试将其添加到 JOptionPane.showInternalMessage(...),但由于我想让该对话框在 3 秒后自动消失,因此这是行不通的,因为 JOptionPane 对话框只会保留在那里,直到有人单击“确定”。

有什么想法吗?非常感谢。

I intend to use a JInternalFrame as a modal JDialog in full-screen mode, however, it is not currently being shown when it gets called. Do I need to add it to some container? I tried adding it to a JOptionPane.showInternalMessage(...), but since I want to make the dialog to go away automatically after 3 seconds, this would not work, as the the JOptionPane dialog would just stay there until someone clicks OK.

Any idea? Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2024-11-16 13:28:39

是的,您必须将其添加到您希望其成为“内部”的容器中。

下面有一个示例向您展示了这种行为。您可以在这里注意到,内部框架(将在框架内按下鼠标时显示/隐藏)不会绘制在 EAST 面板上,因为当它超出其父级的边界时,它会被剪裁。

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class InternalFrameTest extends JPanel
{
    private static final long serialVersionUID = 1L;
    private JInternalFrame internalFrame;
    public InternalFrameTest()
    {
        this.internalFrame = new JInternalFrame("Internal frame");
        internalFrame.setLayout(new FlowLayout());
        internalFrame.add(new JLabel("I am label"));
        internalFrame.add(new JButton("Oi button"));    
        internalFrame.pack();
        add(internalFrame);
    }

    public void showHideInternalFrame()
    {
        internalFrame.setVisible(!internalFrame.isVisible());
    }
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {               
                final InternalFrameTest ift = new InternalFrameTest();
                ift.setBackground(Color.GREEN);
                JFrame f = new JFrame();
                f.addMouseListener(new MouseAdapter() 
                {
                    @Override
                    public void mousePressed(MouseEvent e)
                    {
                        super.mousePressed(e);
                        ift.showHideInternalFrame();
                    }                   
                });
                JPanel cp = new JPanel(new BorderLayout());
                cp.add(ift);
                JPanel eastP = new JPanel();
                eastP.add(new JLabel("EAST"));
                eastP.setBackground(Color.YELLOW);
                cp.add(eastP, BorderLayout.EAST);
                f.setContentPane(cp);
                f.setSize(400, 300);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setVisible(true);
            }
        });
    }
}

Yes you have to add it to a container in which you want it to be 'internal'.

Below you have an example which shows you this behaviour. You can notice here that the internal frame (which will appear/hide on mouse press inside the frame) is not painted over the EAST panel, as it is clipped when it goes outside the borders of its parent.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class InternalFrameTest extends JPanel
{
    private static final long serialVersionUID = 1L;
    private JInternalFrame internalFrame;
    public InternalFrameTest()
    {
        this.internalFrame = new JInternalFrame("Internal frame");
        internalFrame.setLayout(new FlowLayout());
        internalFrame.add(new JLabel("I am label"));
        internalFrame.add(new JButton("Oi button"));    
        internalFrame.pack();
        add(internalFrame);
    }

    public void showHideInternalFrame()
    {
        internalFrame.setVisible(!internalFrame.isVisible());
    }
    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {               
                final InternalFrameTest ift = new InternalFrameTest();
                ift.setBackground(Color.GREEN);
                JFrame f = new JFrame();
                f.addMouseListener(new MouseAdapter() 
                {
                    @Override
                    public void mousePressed(MouseEvent e)
                    {
                        super.mousePressed(e);
                        ift.showHideInternalFrame();
                    }                   
                });
                JPanel cp = new JPanel(new BorderLayout());
                cp.add(ift);
                JPanel eastP = new JPanel();
                eastP.add(new JLabel("EAST"));
                eastP.setBackground(Color.YELLOW);
                cp.add(eastP, BorderLayout.EAST);
                f.setContentPane(cp);
                f.setSize(400, 300);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setVisible(true);
            }
        });
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文