微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否可以让 JInternalFrame 表现得像 JFrame?

如何解决是否可以让 JInternalFrame 表现得像 JFrame?

长话短说,应用程序扩展了 JInternalFrame 对象并实现了各种其他行为和动作。

不幸的是,拥有 JInternalFrame 会生成与父窗口相关的大小限制。拥有 JInternalFrame 的“分离”或“浮动”版本会很棒。诚然,基于 JInternalFrame 的含义,该请求有点自相矛盾,但希望有人偶然发现了一个我似乎还没有找到或找到这样做的独特实现的设置。

以下代码示例有 2 个 JFrame 和 2 个 JInternalFrame。 JFrame 1 有 2 个 JInternalFrame。注意 JFrame 1 的大小是固定的。 JFrame 2 应该模仿新的 JInternalFrame,但它只是表明它太大而无法容纳在 JFrame 1 区域内,因为它的大小是固定的。 JFrame 2 是我希望 JInternalFrame 的行为方式。

有人遇到过类似的情况吗?如果是这样,您可以在哪些方面取得进展以强制改变行为?

import java.awt.event.*; 
import java.awt.*; 
import javax.swing.*; 
class JInteneralFrameTest { 
  
    static JFrame f,f2; 
    static JLabel l,l1; 
  
    public static void main(String[] args) 
    { 
        f = new JFrame("frame"); 
        f.setLayout(new FlowLayout()); 
        JInternalFrame in = new JInternalFrame("frame 1",true,true); 
        JInternalFrame in1 = new JInternalFrame("frame 2",true); 

        JButton b = new JButton("button"); 
        JButton b1 = new JButton("button1"); 
  
        l = new JLabel("This is a JInternal Frame no 1  "); 
        l1 = new JLabel("This is a JInternal Frame no 2  "); 
  
        JPanel p = new JPanel(); 
        JPanel p1 = new JPanel(); 
  
        p.add(l); 
        p.add(b); 
        p1.add(l1); 
        p1.add(b1); 
  
        in.setVisible(true); 
        in1.setVisible(true); 
  
        in.add(p); 
        in1.add(p1); 
  
        f.add(in); 
        f.add(in1); 
  
        f.setSize(300,300); 
        f.show(); 
        f.setResizable(false);
        f2 = new JFrame("frame 2 ");
        JLabel jLabel = new JLabel("I would like my JInternalFrame to be like this");
        f2.add(jLabel);
        f2.setSize(500,500);
        f2.setLocation(50,50);
        f2.show(); 
        
    } 
} 


    import java.awt.event.*; 
    import java.awt.*; 
    import javax.swing.*; 
    class JInteneralFrameTest extends JFrame { 
      
        static JFrame f,f2; 
        static JLabel l,l1; 
      
        public static void main(String[] args) 
        { 
            f = new JFrame("frame"); 
            f.setLayout(new FlowLayout()); 
            JInternalFrame in = new JInternalFrame("frame 1",true); 
            JInternalFrame in1 = new JInternalFrame("frame 2",true); 
    
            JButton b = new JButton("button"); 
            JButton b1 = new JButton("button1"); 
      
            l = new JLabel("This is a JInternal Frame no 1  "); 
            l1 = new JLabel("This is a JInternal Frame no 2  "); 
      
            JPanel p = new JPanel(); 
            JPanel p1 = new JPanel(); 
      
            p.add(l); 
            p.add(b); 
            p1.add(l1); 
            p1.add(b1); 
      
            in.setVisible(true); 
            in1.setVisible(true); 
      
            in.add(p); 
            in1.add(p1); 
      
            f.add(in); 
            f.add(in1); 
      
            f.setSize(300,300); 
            f.show(); 
            f2 = new JFrame("frame 2 ");
            JLabel jLabel = new JLabel("I would like my JInternalFrame to be like this");
            f2.add(jLabel);
            f2.setSize(300,300);
            f2.setLocation(50,50);
            f2.show(); 
            
        } 
    } 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。