[英]JTabbedPane adding null components
Riddle me this: I have a JTabbedPane that has custom JPanels in it. 让我感到困惑:我有一个JTabbedPane,其中包含自定义的JPanels。 When I try and access those JPanels, all I get back is null. 当我尝试访问这些JPanels时,得到的所有内容都是null。 I know that the panels have been added because on the UI I can see the tabs. 我知道已经添加了面板,因为在UI上可以看到选项卡。 I can also interact with the panels and switch between tabs. 我还可以与面板进行交互并在选项卡之间切换。 It doesn't matter how I add these JPanels, it always returns null. 不管我如何添加这些JPanels,它始终返回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. 现在,我可以只保留JPanels的ArrayList进行处理,但是我认为这有点违背JTabbedPane保留任何模型的目的。
Does anyone know what's going on with this? 有谁知道这是怎么回事?
You're using the wrong method: getTabComponentAt(int)
will return the Component
used to render the actual tab itself (if you've specified one). 您使用了错误的方法: getTabComponentAt(int)
将返回用于呈现实际选项卡本身的Component
(如果已指定)。 You should call getComponentAt(int)
instead. 您应该改为调用getComponentAt(int)
。 I've done exactly the same thing myself before! 我以前做过完全相同的事情!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.