PDA

View Full Version : Switching panels



ror
19 Aug 2009, 12:15 AM
Hello,

I have class with panel definition


public class MyPanel extends ContentPanel{

MyPanel(String Title){
this.setHeading(Title);
}
}

and Viewport class


public class ViewportEx extends Viewport {
ContentPanel left;
ContentPanel main;

public ViewportEx() {
left = new MyPanel("Menu");
main = new MyPanel("First main");

this.setLayout(new RowLayout(Orientation.HORIZONTAL));

this.add(left, new RowData(.3, 1));
this.add(main, new RowData(.7, 1));

Timer t = new Timer() {

@Override
public void run() {

main.removeFromParent();
//??
//how to put other MyPanel in place of main?
//even if I use method add() from ViewportEx
//is doesen't showing on ViewportEx
//??
}
};
t.scheduleRepeating(3000);
}
}



I place Viewport on RootPanel, on this Viewport I have 2 panels:
1) menu with links
2)main panel with content

Depend what link I click on menu panel I want load others panels on second panel. I know how to remove but when I add second panel it didn't display on screen.
When I use tabpanel and tabItem I can add panel dynamically, but I don't want to use this widget. Maybe someone know how I can resolve this problem.

ror
19 Aug 2009, 1:12 AM
my solution:


public class ViewportEx extends Viewport {

ContentPanel left;
ContentPanel main;

public ViewportEx() {


left = new MenuPanel();
main = new MainPanel();

this.setLayout(new RowLayout(Orientation.HORIZONTAL));

this.add(left, new RowData(.3, 1));
this.add(main, new RowData(.7, 1));



Timer t = new Timer() {

@Override
public void run() {
ViewportEx vpex =(ViewportEx)main.getParent();
main.removeFromParent();
main = new MainPanel2();

vpex.add(main, new RowData(.7, 1));
vpex.layout();

}
};
t.scheduleRepeating(3000);
}
}


Maybe someone want to add something to this?

takayser
20 Aug 2009, 10:22 PM
have a look at CardLayout, this is what you need.