我还尝试将标签封装在dekstop窗格中。但是闪现的消息不能将组件封装在非空容器中。如有任何帮助,不胜感激
发布于 2019-06-10 22:35:02
使用Netbeans 11.0时,我可以将JLabel拖到JDesktopPane中,并且没有看到您报告的错误。然而,我相信JDesktopPane只是被设计成JInternalFrame的容器,而不是直接嵌入其他组件。这是针对MDI应用程序的,这些应用程序现在已经很少出现了。请查看相关的Swing Tutorial以了解背景信息。我还在此处提供了一个最小示例,您可以将其粘贴到Netbeans中的空类中
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JDesktopPane desktop_pane = new JDesktopPane();
frame.getContentPane().add(desktop_pane);
for (int i = 1; i <= 5; ++i) {
JInternalFrame internal = new JInternalFrame(String.format("Window %d", i), true, true, true, true);
internal.setSize(150, 80);
internal.setLocation(i * 50, i * 50);
internal.setVisible(true);
desktop_pane.add(internal);
}
desktop_pane.setPreferredSize(new Dimension(800, 600));
frame.pack();
SwingUtilities.invokeLater(() -> {
frame.setVisible(true);
});
}它将创建一个桌面,其中包含五个可调整大小的窗口。
https://stackoverflow.com/questions/56500555
复制相似问题