Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

component.removeAll() that doesnt work  RSS feed

 
eric vitallis
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i have this problem, once again i have a splitpane that has 2 scrollpanes on the left and on the right.the left scrollpane contains a tree and the right sp contains a jpanel that displays various components depending on the node selected.
the problem is , when selected , everything seems to work fine until the retrieval of the gui in the userObject (userObjec.getGui() returns a jpanel containing components).To display the gui i do something like:

//first display
guiPanel = new JPanel(new BorderLayout());
guiPanel.add(uo.getGUI(), BorderLayout.PAGE_START);

//after an event in the valueAdded() method of treeSelectionListener
//******the problem is here

guiPanel.removeAll();
guiPanel.add(uo.getGUI(), BorderLayout.PAGE_START);
guiPanel.validate();

no uo.getGui() returns the correct jpanel (i did a print() ) , but the remove all doesnt seem to work well because at times ,the component displayed on the right is the correct one and at times it doesn't change.. which seems bizzaire..

any ideas.. hoping i was clear enuff

thanks in advace
 
eric vitallis
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it gets worse.., with this:

guiPanel.removeAll();
guiPanel.add(uo.getGUI(), BorderLayout.PAGE_START);
guiPanel.validate();

it doesnt really rub off the stuff on guiPanel, so if anything is added ,
it appears on top of the components that were to be removed...
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pack you frame each time you add/remove components to it


like frame.pack();
 
eric vitallis
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot for , the reply, i got another urgent assignement and i had to work on that first.

ok,the pb is that all is first put in a panel before finally placing the panel in a frame.I therefore dont have access to the frame at that point(in the code)..
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
often, when using validate()
guiPanel.validate();

you also need to call
guiPanel.repaint(); //or just repaint();

if that is no better, post your code - if it's not too large.
if it is a large file, create a small demo program that
demonstrates the problem.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"eric",

Please review the JavaRanch name policy and change your display name.
 
eric vitallis
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for the name John, i have updated my profile.

Thanks Dan for the reply , am going to try that, thanks
 
eric vitallis
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot ! guiPanel.validate(), followed by repaint() worked, and all the different "gui"s are displayed accordingly, thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!