java - JPanel 在另一个 JPanel 的函数中的大小
问题描述
我想调整JPanel
包含它的另一个面板的功能的大小。
当我运行我的代码时,面板很小并且位于内容面板的顶部。
所以这是我的代码:
package test;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class CodeForStackOverFlow {
public static void main(String[] args) {
Frame frame = new Frame();
}
}
class Frame extends JFrame {
private class Panel extends JPanel {
private JPanel content = new JPanel();
Panel() {
content.setBackground(Color.red);
this.add(content);
}
void adjustSize() {
this.content.setSize(new Dimension(this.getHeight(), this.getHeight()));
}
}
private Panel contentPane = new Panel();
Frame() {
this.setSize(new Dimension(500, 400));
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setContentPane(contentPane);
contentPane.adjustSize();
this.setVisible(true);
}
}
解决方案
推荐阅读
- google-cloud-platform - 将文件从 VM 复制到 GCP 上的云存储桶
- python - ffmpeg 通过管道传输到 python 并显示 cv2.imshow 向右滑动并更改颜色
- ios - Firebase 云消息未发送到 iOS(停留在“预定”状态)
- git - 如何更改 HEAD 指向的远程分支?
- php - 在 Laravel 中使用不同的 redis 连接来处理作业
- upload - Jersey File Upload中FormDataContentDisposition的问题
- html - 如何创建轮播滑块推荐
- c# - 保护用 .Net 4.7 编写的 WPF 应用程序的代码
- c++ - 包含指向指针的对象的深层副本
- r - 为什么 R 不能通过词法作用域找到参数的值?