访问 JScrollPane 中的 JTextArea
我在 JTabbedPane 的(多个)JScrollPane 中有一个 JTextArea。
我需要访问 JTextArea。如果我没有 JScrollPane,我可以这样做:
JTextArea c = (JTextArea)jTabbedPane1.getComponentAt(i);
在 JScrollPane 中时如何获取它?
干杯, 加兹勒。
I have a JTextArea in (multiple) JScrollPane in a JTabbedPane.
I need to access the JTextArea. If I didn't have the JScrollPane, I could do:
JTextArea c = (JTextArea)jTabbedPane1.getComponentAt(i);
How would I get it when in a JScrollPane?
Cheers,
Gazler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你会在那里遇到一堆混乱的参考资料(至少我过去就遇到过这种情况)。
我建议您有一个中间对象来负责这些依赖项,并将“业务”方法移到那里。
因此,您可以使用此具有引用的对象,而不是添加组件并丢失引用(或者最糟糕的是,在各处复制引用):
请参阅 调解器 设计模式。重点是将所有“视图”对象从它们所在的位置(通常作为子类中的引用)移动到公共中间对象。
Sounds like you'll get into a mess of references over there ( at least that's what have happened to me in the past ) .
I would suggest you to have a middle object in charge of those dependencies for you and to move the "business" methods there.
So instead of adding components and losing the references ( or worst, duplicating the references all over the place ) you can use this object which will have the reference:
See the Mediator design pattern. The focus is to move all the "view" objects from where they are ( usually as references in subclasses ) to a common intermediate object.
这条线看起来很复杂,但我认为这样就可以了。
但我认为将
TextArea
存储在ArrayList
中会更有趣。所以你可以这样做:
创建一个新的就像这样:
希望这会有所帮助。
This line looks complex, but I THINK this would do it.
But I think it would be more interesting to store your
TextArea
's in anArrayList
.So you can do this:
Create a new one is something like this:
Hope this helps.
我更喜欢 AppMediator 方法,但你也可以这样做
I prefer the AppMediator approach but you could also do