ColumnContainer does not remove last child well
Brought to you by:
peastman
Hi,
the following code ( just compile and run add a few sections by pressing the add section button and then remove the text from the last section , you will see that the last section does not appear ) the removing works perfectly for any other non-last section.
Cheers,
T.
Here is the code,
crucial place is after the comment //Delete if there is no text
import buoy.event.*;
import buoy.widget.*;
import java.awt.Rectangle;
public class Demo
{
public static void main(String args[])
{
System.out.println( "Okay..." );
final BFrame f = new BFrame();
BorderContainer content = new BorderContainer();
BToolBar toolBar = new BToolBar( BToolBar.HORIZONTAL );
final ColumnContainer cc = new ColumnContainer();
addSection( cc );
ExplicitContainer addSectionC = new ExplicitContainer();
BButton addSection = new BButton("Add Section");
addSectionC.add(addSection , new Rectangle( 130 , 20 ));
toolBar.add( addSectionC );
f.setContent(content);
content.add( cc , BorderContainer.CENTER);
content.add( toolBar , BorderContainer.NORTH );
RowContainer rc = new RowContainer();
addSection.addEventLink(CommandEvent.class, new Object() {
void processEvent()
{
addSection( cc );
cc.layoutChildren();
}
});
f.addEventLink(WindowClosingEvent.class, new Object() {
void processEvent()
{
System.exit(0);
}
});
f.pack();
f.setVisible(true);
//For giggles, make it slightly taller
f.setBounds( new Rectangle( 275 , 275 ) );
}
public static void addSection( ColumnContainer cc ){
BTextArea ba = new BTextArea();
ba.setRows(1) ;
ba.setColumns(20);
ba.setWrapStyle( BTextArea.WRAP_WORD );
ba.addEventLink(ValueChangedEvent.class, new Object() {
void processEvent( ValueChangedEvent e )
{
BTextArea o= (BTextArea)e.getWidget();
//Delete if there is no text
if( o.getText().equals("") ){
ColumnContainer cc = (ColumnContainer)o.getParent();
cc.remove( o );
cc.layoutChildren();
}else{
//Expand section if there was a new line
o.setRows( o.getText().split("\\n").length );
o.getParent().layoutChildren();
}
}
});
//ba.addEventLink(WidgetMouseEvent.class, popup, "show");
ba.setText( " " );
cc.add( ba );
}
}
It actually is getting removed correctly. The problem is that the window isn't getting repainted, so it still looks like it's there. If you add the line
cc.getParent().repaint();
immediately after
cc.layoutChildren();
then it works fine. So the question is, should the window automatically get repainted after you make any changes to its contents?