Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Getting text from swiing components

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting some text from a layer of swing components that are several layers deep. I'll enclose the current code. Is there a way to genericly get the text without knowing what makes up the layers of components? This isn't the exact
code but it shows how it gets down to the text.
==================================================
JInternalFrame currentcomponent
Container qad = currentcomponent.getContentPane();
if(qad == null)
{
return;
}
Component compList[] = qad.getComponents();
if(compList [0] == null)
{
return;
}
JPanel jp = (JPanel)compList [0];
if(jp == null)
{
return;
}
compList = jp.getComponents();
if(compList[0] == null)
{
return;
}
JScrollPane sp = (JScrollPane)compList [0];
if(sp == null)
{
return;
}
compList = sp.getComponents();
if(compList[0] == null)
{
return;
}
JViewport vp = (JViewport)compList [0];
if(vp == null)
{
return;
}
compList = vp.getComponents();
if(compList[0] == null)
{
return;
}
JTextPane tp = (JTextPane)compList [0];
if(tp == null)
{
return;
}
Document doc = tp.getDocument();
String lineOfText = tp.getText();
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Barry,
As far as I know, all the swing text components (including "JTextPane" -- from your example), extend the JTextComponent class.
Therefore, I suggest you simply test whether the particular component is an instance of "JTextComponent". Something like this (note: untested)

Hope it helps.
Good Luck,
Avi.
[ June 09, 2003: Message edited by: Avi Abrami ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic