JTabbedPane 添加空组件
猜谜语:我有一个 JTabbedPane,里面有自定义 JPanel。当我尝试访问这些 JPanel 时,我得到的只是 null。我知道面板已添加,因为在 UI 上我可以看到选项卡。我还可以与面板交互并在选项卡之间切换。无论我如何添加这些 JPanel,它总是返回 null。
现在我可以将 JPanel 的 ArrayList 保留在一边进行处理,但我认为这会有点违背 JTabbedPane 保留任何类型模型的目的。
有谁知道这是怎么回事?
Riddle me this: I have a JTabbedPane that has custom JPanels in it. When I try and access those JPanels, all I get back is null. I know that the panels have been added because on the UI I can see the tabs. I can also interact with the panels and switch between tabs. It doesn't matter how I add these JPanels, it always returns null.
Now I could just keep an ArrayList of the JPanels on the side for processing, but I would think that would kinda defeat the purpose of the JTabbedPane keeping any kind of model.
Does anyone know what's going on with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的方法:
getTabComponentAt(int)
将返回用于呈现实际选项卡本身的Component
(如果您已指定)。您应该改为调用getComponentAt(int)
。我自己以前也做过同样的事情!You're using the wrong method:
getTabComponentAt(int)
will return theComponent
used to render the actual tab itself (if you've specified one). You should callgetComponentAt(int)
instead. I've done exactly the same thing myself before!