本文介绍了访问JScrollPane中的JTextArea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JTabbedPane的(多个)JScrollPane中有一个JTextArea。
I have a JTextArea in (multiple) JScrollPane in a JTabbedPane.
我需要访问JTextArea。如果我没有JScrollPane,我可以这样做:
I need to access the JTextArea. If I didn't have the JScrollPane, I could do:
JTextArea c = (JTextArea)jTabbedPane1.getComponentAt(i);
在JScrollPane中如何获得它?
How would I get it when in a JScrollPane?
干杯,
Gazler。
Cheers,Gazler.
推荐答案
这条线看起来很复杂,但我 THINK 这样就可以了。
This line looks complex, but I THINK this would do it.
JTextArea c = (JTextArea) (((JViewportView) (((JScrollPane) jTabbedPane1.getComponentAt(i)).getViewport()))).getView();
但我认为存储 TextArea $会更有趣c $ c>在
ArrayList
中。
所以你可以这样做:
But I think it would be more interesting to store your TextArea
's in an ArrayList
.
So you can do this:
List<JTextArea> listAreas = new ArrayList<JTextArea>();
...
JTextArea c = listAreas.get(i);
创建一个新的是这样的:
Create a new one is something like this:
JTextArea c = new JTextArea();
jTabbedPane1.addTab("Title", new JScrollPane(c));
listAreas.add(c);
希望这会有所帮助。
这篇关于访问JScrollPane中的JTextArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!