java - JLabel not showing up
问题描述
For some reason my JLabel
isn't displaying and I can't figure out why
(editString DOES have a value).
compFrame.removeAll();
JPanel editPane = new JPanel();
editPane.setLayout(new GridLayout(0,1));
compFrame.add(editPane);
//JLabel lastValue = new JLabel(editString);
editPane.add(new JLabel(editString));
compFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
compFrame.setVisible(true);
解决方案
您应该在 ContentPane 上使用 removeAll。尝试这个
compFrame.getContentPane().removeAll();
removeAll 的 API 文档说:
此方法更改与布局相关的信息,因此使组件层次结构无效。如果容器已显示,则必须随后验证层次结构以反映更改。
推荐阅读
- arrays - 如何确保数组中的所有元素都是唯一的?
- html - 如何使 div 内容不会过度扩展
- javascript - 如何路由嵌入了查询字符串的搜索 URL?
- python - 如何在 Python 中按组执行 proc rank(SAS 函数)?
- php - 在 PHP 中按键和求和值对多维数组进行分组
- c# - Xamarin 管理未处理的异常
- asp.net - 为什么 Base64 字符串在 Message Box 中显示为空?
- python - 获取 dict 每个项目并在一行中获取一个新列表
- magnolia - 将 Magnolia 从企业版迁移到社区版
- chef-infra - 如何强制 Chef 的 yum_repository 资源使用“makecache fast”?