Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2006

Tip: Looking for answers? Try searching our database.

JComponents

Thread view: 
freesoft_2000 - 30 Mar 2006 19:04 GMT
Hi everyone,

             You see i have some embedded JComponents in a JTextPane, now
what i want i want to do is remove the embedded components and then add
them back to their original location(i.e where i got them from in the
first palce)

You see to get the all JComponents i do this

JTextpane TextPane1 = new JTextPane;
JLabel Label1 = new JLabel("Label 1");

int j = 0;
int i = 0;

j = TextPane1.getComponentCount();

for(i=0;i<j;i++)
{

Label1 = (JLabel)((Container)TextPane1.getComponent(i)).getComponent(0);

//Now this is the part i want to remove and
//add back the JComponent to its original palce

TextPane1.remove(i);

//The below part seems to be wrong as the
//JComponent is not added at the correct places.
TextPane1.add(Label1);

//The below command line also did not work

//TextPane1.add(i);
}

I have a feeling that i should not be using the
TextPane1.add(); set of methods but i am really not sure what else to use
to insert the JComponent to the original place in the document where i got
it from.

I really hope someone can help me with this problem

Thank You

Yours Sincerely

Richard West
Monique Y. Mudama - 30 Mar 2006 20:43 GMT
> Hi everyone,
>
>               You see i have some embedded JComponents in a JTextPane, now
> what i want i want to do is remove the embedded components and then add
> them back to their original location(i.e where i got them from in the
> first palce)

[snip]

> //The below part seems to be wrong as the
> //JComponent is not added at the correct places.
> TextPane1.add(Label1);

My guess here is that some layouts are sensitive to the order in which
you add components, and others are not.  I don't know what the default
layout for a JTextPane is, but it might be FlowLayout, in which case
a call to add() will always plop the component into the next spot to
the right of whatever else is already there.

You might have more luck with a layout in which you have more control,
like (much as I hate it) GridBagLayout.

Signature

monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.