gpt4 book ai didi

java - 在执行时将 JInternalFrame 添加到 JDesktopPane

转载 作者:行者123 更新时间:2023-11-29 10:20:17 25 4
gpt4 key购买 nike

我在使用 JDesktopPane 时遇到问题,我在其上添加了 JInternalFrame,然后在 JFrame 上显示它。

问题是当我尝试在执行时添加另一个 JInternalFrame 时。

我使用相同的方法添加相同的 JInternalFrame 但它的 dosnt 出现了。

public class Desktop extends JDesktopPane {
(...)
public void addJInternalFrameBox(JInternalFrameBox jifb) {
this.add(jifb, desktop.CENTER_ALIGNMENT);
this.repaint();
this.validate();
}
}

JInternalFrameBox 类:

public class JInternalFrameBox extends JInternalFrame {
(...)
public JInternalFrameBox(Integer id) {
this.id = id;
setUpFrame();
}
public void setUpFrame() {
JLabel lbl = new JLabel("test");
lbl.setVisible(true);

this.add(lbl);
this.setPreferredSize(INTERNAL_FRAME_SIZE);
this.setLocation(100, 100);
this.setIconifiable(true);
this.setClosable(true);
this.pack();
this.setVisible(true);
}
}

jButtonBox 打开 JInternalFrameBox 的按钮:

public class jButtonBox extends JButton implements MouseListener {
public void mouseReleased(MouseEvent e) {
JInternalFrameBox jifb = new JInternalFrameBox(id);
jifb.setVisible(true);
Desktop df = Desktop.getInstance();
df.addJInternalFrameBox(jifb);
}
(...)
}

最佳答案

阅读 How to Use Internal Frames 上的 Swing 教程部分一个工作示例。

关于java - 在执行时将 JInternalFrame 添加到 JDesktopPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7531348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com