是否可以将带有轮廓和绘制内容的 JPanel 添加到 JInternalFrame 中?换句话说,类似于以下内容:
JFrame frame = new JFrame();
JDesktopPane desktop = new JDesktopPane();
JInternalFrame iframe = new JInternalFrame();
JPanel panel = new JPanel();
iframe.setVisible(true);
iframe.setSize(new Dimension(300, 200));
iframe.add(panel)
desktop.add(iframe);
frame.setContentPane(desktop);
panel.setBorder(BorderFactory.createLineBorder(Color.black));
panel.setBounds(0, 0, 100, 100);
并且在绘制函数中(在 JFrame 类内)有
public void paint(Graphics graphics){
graphics.//insert method
}
并且仍然显示在 JInternalFrame 的面板内。
无论出于何种原因,JPanel 和任何绘画功能都没有出现。有人可以帮助我理解如何实现这一点或解释我做错了什么吗?
最佳答案
and in the paint function (within the JFrame class) have
public void paint(Graphics graphics){
graphics.//insert method
}
不要重写 JFrame 的 Paint() 方法。很少有任何理由这样做。这会导致问题,因为您破坏了绘制方法,现在子组件将不会被绘制。
JInterrnalFrame 就像 JFrame(或 JDialog)。您可以向其中添加任何组件。
iframe.setVisible(true);
iframe.setSize(new Dimension(300, 200));
iframe.add(panel)
此外,在使框架可见之前向框架添加组件。然后布局管理器就可以完成他们的工作。
关于java - 将 JPanels 和绘画添加到 JInternalFrames,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33060219/