2
votes

I had used gridLayout with 2 columns. When i search(code is below), the textArea component stays in its own possition. Those which are hidden also take their places. If i use boxLayout instead of gridLayout, it works fine but there is only one column.

problem after searching

enter image description here

Container wrapContainerMinute = new Container(new GridLayout(connection.responseMenu.size() / 2+1, 2));
f.add(wrapContainerMinute);
for (Map<String, Object> entrySet : connection.responseMenu) {
    String tableName = (String) entrySet.get("name");

    Container singleMinuteMenuContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    TextArea minuteTextArea = new TextArea(tableName);
    minuteTextArea.setEditable(false);
    minuteTextArea.getAllStyles().setAlignment(Label.CENTER);
    minuteTextArea.setScrollVisible(false);
    minuteTextArea.setRows(20);
    minuteTextArea.setGrowByContent(true);
    minuteTextArea.setGrowLimit(2);
    singleMinuteMenuContainer.add(minuteTextArea);
}

minuteSearchTextField.addDataChangeListener(new DataChangedListener() {

@Override
public void dataChanged(int type, int index) {
    String searchTableName = minuteSearchTextField.getText().toLowerCase();
    boolean show = false;
    for (Component c : wrapContainerMinute) {
        Container searchedContainer = (Container)c;
        TextArea searchedTextArea = (TextArea) searchedContainer.getComponentAt(0);
        c.setVisible(true);
        if (searchedTextArea.getText().toLowerCase().indexOf(searchTableName)>-1) {
            show = searchedTextArea.getText().toLowerCase().indexOf(searchTableName)>-1;
            c.setHidden(!show);
            c.setVisible(show);
        }else{
            show = searchedTextArea.getText().toLowerCase().indexOf(searchTableName) > -1;
            c.setHidden(!show);
            c.setVisible(show);
        }
    }
    wrapContainerMinute.animateLayout(1500);
}
});
1

1 Answers

1
votes

The setHidden is giving the component a (0,0) preferred size which hides the Component, GridLayout ignores the Components preferred size because it splits the Container to equal sized cells. What you need to do is to remove and add the Components instead of using the setHidden