java - BoxLayout can't be shared 错误,试图在一个 JFrame 中容纳两个 JPanel
问题描述
试图在一个框架中放置 2 个面板,一个小的面板在顶部,一个填充框架的其余部分。但是,此代码返回“无法共享 BoxLayout”错误。
JFrame frame = new JFrame("Clients");
frame.setSize(1000,900);
JPanel sorters = new JPanel();
sorters.setSize(1000, 100);
frame.getContentPane().add(sorters);
JPanel rowPane = new JPanel();
JScrollPane scrPane = new JScrollPane(rowPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrPane.setSize(1000, 800);
frame.getContentPane().add(scrPane);
frame.getContentPane().setLayout(new BoxLayout(frame, BoxLayout.Y_AXIS));
解决方案
ABoxLayout
必须将其应用到的实际容器作为第一个参数,在您的情况下,容器是 frame 的 contentPane:
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
推荐阅读
- django - 来自 AND 操作和顺序过滤器的 Django diffrenet 结果
- c - Frama-C:找到循环结束的位置
- android - 自定义按钮背景 [ANDROID]
- android - 如何使工具栏中的后退按钮位于工具栏的右侧?
- mysql - 错误 1054 (42S22):“where 子句”中的未知列“”
- powerbi - Power BI Dax 多个 IF AND 语句
- python - JModelica 结合 CasADi 在 Python 中获得线性化模型
- azure - Azure Bot 未在 Skype 上运行
- php - 致命错误:未捕获错误:调用未定义的方法 Phinx\Db\Adapter\MysqlAdapter::getCakeConnection()
- javascript - while循环中的if语句