java - How to add a background Image on JPanel without extending?
问题描述
I want to add a background image on the panel. Most of the answers here says that you should use JLabel
or extend a JPanel
to use the paintComponent
.
However in my project I used IntelliJ IDEA, with its GUI builder. Through the GUI builder I made my class extend through JFrame
. Hence I can't use the extend panel method.
Here's how I have my class with its extending frame.
public class StoryFrame extends JFrame {
private JPanel mainPanel;
public StoryFrame(){
this.setContentPane(mainPanel);
}
}
I want to have mainPanel
have its own background image.
I used a GridLayout
so overlapping Swing Components also isn't an option.
Any other methods on how can we add a background image on a panel?
解决方案
推荐阅读
- java - 是否有 INDArray 的方法来执行两个 INDArray(具有不同大小)的相加?
- database - 在 node-oracledb 中使用事务
- c# - 无法从 c# 代码调用类模板的非虚拟函数
- ruby-on-rails - form_for 'file_field' 未显示在编辑操作中选择的文件
- javascript - Element 的 Microsoft Edge 实例返回的结果与 chrome/firefox 不同
- java - 如何修复 RecylerView 布局中按钮的位置?我不希望按钮与 RecyclerView 中的图像一起滚动
- r - 带有插入符号的决策树中属性使用的奇怪结果
- go - syscall.Entersyscall 的实现在哪里?
- atlassian-sourcetree - 从 gitignore 提交更改
- javascript - 确定在反应中选中的复选框的方法(useState)