GWT, Got Error in Swaping panel from EAST to WEST in DockPanel & via versa?

StackOverflow https://stackoverflow.com/questions/16207366

  •  11-04-2022
  •  | 
  •  

سؤال

This code got error

@Override
public void onClick(ClickEvent event) {
    // TODO Auto-generated method stub
    mainDockPanel.remove(panel1);
    mainDockPanel.remove(panel2);
    if(mainDockPanel.getWidgetDirection(panel1).equals(DockPanel.EAST)){
        mainDockPanel.add(panel1, DockPanel.WEST);
        mainDockPanel.add(panel2, DockPanel.EAST);
    }
    else if (mainDockPanel.getWidgetDirection(panel1).equals(DockPanel.WEST)){
        mainDockPanel.add(panel1, DockPanel.EAST);
        mainDockPanel.add(panel2, DockPanel.WEST);
    }
}

Somethign wrong with this code?

Also, is there any other better solution to swap 2 panel?

هل كانت مفيدة؟

المحلول

First you removed panel1 from mainDockPanel. Then you use if(mainDockPanel.getWidgetDirection(panel1).equals(DockPanel.EAST)){ From the API docs

the widget's layout direction, or null if it is not a child of this panel Blockquote

Chances are, you are getting a NPE

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top