从jTabbbedPane的选定选项卡中获取jTextPane [英] Getting jTextPane from selected tab of jTabbbedPane

查看:148
本文介绍了从jTabbbedPane的选定选项卡中获取jTextPane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是java Swing的新手.我正在尝试开发一个工具,其中使用了Jtextpane作为编辑器. Jtextpane包含在Jtabbedpane中以满足我的要求.但是我已经将JTextpane插入到Jscrollpane中,然后插入到Jtabbedpane中.现在,当我选择一个特定的选项卡时,我应该获得相应的Jtextpane.我用过

jTabbedPane.getSelectedComponent();

但是它返回Jscrollpane.因此,我无法将内容保存在相应的Jtextpane中...

有人可以帮我解决这个问题吗?...

在此先感谢...

I am new to java Swing. I am trying to develop a tool, in which I used a Jtextpane as an editor. Jtextpane is enclosed in a Jtabbedpane to meet my requirement. But I have inserted the JTextpane in a Jscrollpane and then to the Jtabbedpane. Now, when I select a particular tab, I should get the corresponding Jtextpane. I have used the

jTabbedPane.getSelectedComponent();

But it returns the Jscrollpane. So, I am unable to save the contents in corresponding Jtextpane...

Can anybody plz help me to resolve this....

Thanks in Advance...

推荐答案

可以使用JScrollPanegetComponent(int)方法获取JTextPane吗?我假设如果JTextPane 是滚动窗格中的唯一组件,则将0 传递给getComponent(int)会得到JTextPane.
Can you use the JScrollPane''s getComponent(int) method to get the JTextPane? I''d presume that if the JTextPane is the only component in the scroll pane, passing 0 to getComponent(int) would give you the JTextPane.


首先获取选项卡(滚动面板)的选定组件:
How about first getting the selected component of the tab (which is the scroll panel):
JScrollPane jscrollpane =(JScrollPane)jTabbedPane.getSelectedComponent();



然后获取该组件的选定组件(将是文本面板):



And then get the selected component of that (which would be the text panel):

JTextPane jtextpanel=(JTextPane)jscrollpane.getSelectedComponent();



为了安全起见,您应该进行一些类型检查.另外,您可以使用getComponents 创建递归方法,以在选项卡或滚动面板上找到所需的文本面板.

祝你好运!



You should do some type checking though to be safe. Also, you could create a recursive method using getComponents to find the desired text panel on the tab or scroll panel.

Good luck!


这篇关于从jTabbbedPane的选定选项卡中获取jTextPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆