Topic: JTabbedPane中如何得到当前的组件?

  Print this page

1.JTabbedPane中如何得到当前的组件? Copy to clipboard
Posted by: flyingswan
Posted on: 2005-06-11 17:34

我在JTabbedPane中用addtab()方法加入了JSCrollPane,然后在JScrollPane中加入了JTextArea 如下

JTextArea dataTextArea = new JTextArea(“haha",10,20);
JScrollPane dataScrollPane = new JScrollPane(dataTextArea);
tableScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
JTabbedPane dataTabPane = new JTabbedPane();
dataTabPane.addTab("1",dataScrollPane);
dataTabPane.addTab("2",dataScrollPane);
dataTabPane.addTab("3",datacrollPane);

dataTabPane有好几个tab,也就是有好几个选项卡,当选中一个选项卡时,比如选中1号选项卡,如何使得dataTextArea变成当前选项卡中的textArea?

我可以用如下的方法得到当前的dataScrollPane:
dataScrollPane =((JScrollPane) dataTabPane.getComponentAt(index));
再怎么做才能得到当前ScrollPane中的textArea???
谢谢

2.Re:JTabbedPane中如何得到当前的组件? [Re: flyingswan] Copy to clipboard
Posted by: 钟瑾
Posted on: 2005-06-17 08:52

JTextArea textArea =(JTextArea) dataScrollPane.getViewport().getView();


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923