Reputation: 5192
I am trying to display rows with the same height filed with container and the container contains texts/images. I am trying to display table list for this.
see the image below.
I would like to display rows with the same height.
Below is the code which i have been used. I have used Swipable container as table row.
tableContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
tableContainer.setUIID("transparent");
//Table Header - Start
Container tableHeaderRowContainer = new Container();
tableHeaderRowContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
tableHeaderRowContainer.setScrollable(false);
tableHeaderRowContainer.setUIID("TableHeaderBg");
Container tableHeaderContainer = new Container(new TableLayout(1,columnNames.length));
tableHeaderContainer.setScrollable(false);
tableHeaderContainer.setUIID("TableHeaderBg");
for(int col=0;col<columnNames.length;col++){
final String colName = columnNames[col];
Container headerContainer = new Container();
headerContainer.setUIID("TableHeaderBg");
Button headerButton = new Button();
SpanLabel headerTitle = new SpanLabel(colName);
headerTitle.setTextUIID("TableHeader");
headerTitle.setUIID("TableHeader");
headerContainer.addComponent(headerTitle);
headerContainer.setFocusable(false);
headerContainer.setLeadComponent(headerButton);
headerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
}
});
// tableHeaderContainer.add(l1);
TableLayout.Constraint constraint = ((TableLayout)tableHeaderContainer.getLayout()).createConstraint();
constraint = ComponentUtils.setTableConstraint(constraint, col);
tableHeaderContainer.addComponent(constraint,headerContainer);
}
selectAllCheckBox = new CheckBox();
selectAllCheckBox.setUIID("TableHeaderCheck");
tableHeaderRowContainer.addComponent(selectAllCheckBox);
tableHeaderRowContainer.addComponent(tableHeaderContainer);
tableContainer.addComponent(tableHeaderRowContainer);
//Table Header - End
//Table list - start
Container tableContainerMain = new Container();
tableContainerMain.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
tableContainerMain.setScrollableY(true);
for(int row=0;row<data.length;row++){
String jobReference = jobRefList[row];
Container tableRowContainer = new Container();
tableRowContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
tableRowContainer.setScrollable(false);
Button actionButton = new Button();
final Container rowContainer = new Container(new TableLayout(1,columnNames.length));
if(row%2==0){
rowContainer.setUIID("even");
tableRowContainer.setUIID("evenPadding");
}
else{
rowContainer.setUIID("odd");
tableRowContainer.setUIID("oddPadding");
}
rowContainer.setFocusable(false);
rowContainer.setLeadComponent(actionButton);
JobDataDetail jobRef = editJobs[row];
final JobData jobDataRef = Utility.getJobDataWithStatus(jobData);
jobDataRef.setJobDataDetail(jobRef);
for(int col=0;col<columnNames.length;col++){
Label statusLabel = new Label();
String imageName = "";
if(data[row][col]!=null && (data[row][col].toString().equalsIgnoreCase(Constants.STATUS_ACTIVE)
|| data[row][col].toString().equalsIgnoreCase(Constants.STATUS_REACTIVE))){
imageName = "st-completed.png";
}
else if(data[row][col].toString().equalsIgnoreCase(Constants.STATUS_ACTIVE_NONCOMPLETE)){
imageName = "st-incomplete.png";
}
else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_PENDING) ){
imageName = "st-pending.png";
}
else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_SYNCED) ){
imageName = "st-synched.png";
}
else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_CHECKIN) ){
imageName = "st-checkedin.png";
}
else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_CLOSED) ){
imageName = "st-closed.png";
}
if(!Utility.isBlankOrNull(imageName)){
statusLabel = new Label(res.getImage(imageName));
if(row%2==0){
statusLabel.setUIID("evenImageLabel");
}
else{
statusLabel.setUIID("oddImageLabel");
}
statusLabel.setVerticalAlignment(Label.TOP);
Container labelContainer = new Container();
if(row%2==0){
labelContainer.setUIID("even");
}
else{
labelContainer.setUIID("odd");
}
labelContainer.addComponent(FlowLayout.encloseIn(statusLabel));
TableLayout.Constraint constraint1 = ((TableLayout) rowContainer.getLayout()).createConstraint();
constraint1 = ComponentUtils.setTableConstraint(constraint1, col);
rowContainer.addComponent(constraint1, labelContainer);
}
else{
/*
SpanLabel txtLabel = new SpanLabel((String) data[row][col]);
txtLabel.setTextUIID("login_title");
txtLabel.setUIID("transparent");*/
TextArea txtLabel = new TextArea((String) data[row][col]);
txtLabel.setUIID("login_title");
txtLabel.setEditable(false);
txtLabel.setRows(2);
txtLabel.setScrollVisible(false);
TableLayout.Constraint constraint1 = ((TableLayout) rowContainer.getLayout()).createConstraint();
constraint1 = ComponentUtils.setTableConstraint(constraint1, col);
rowContainer.addComponent(constraint1, txtLabel);
}
SwipeableContainer swipeableContainer = new SwipeableContainer(null,actionButtons[row], rowContainer);
swipeableContainer.setUIID("transparent");
swipeableContainer.setSmoothScrolling(true);
swipeableContainer.setSwipeActivated(true);
Container checkContainer = new Container();
if(row%2==0){
checkContainer.setUIID("even");
}
else{
checkContainer.setUIID("odd");
}
CheckBox c = new CheckBox();
c.setName(jobReference);
if(row%2==0){
c.setUIID("evenCheck");
}
else{
c.setUIID("oddCheck");
}
c.setVerticalAlignment(TOP);
checkBoxArr.add(c);
checkContainer.addComponent(FlowLayout.encloseIn(c));
tableRowContainer.addComponent(checkContainer);
tableRowContainer.addComponent(swipeableContainer);
tableContainerMain.addComponent(tableRowContainer);
}
}
tableContainer.addComponent(tableContainerMain);
//Table list - End
addComponent(BorderLayout.CENTER, tableContainer);
Edited:
I have applied solution given by diamond, but still it seems not solved as it has to be.
see in the image, the third line seen upto the given height.
Upvotes: 1
Views: 67
Reputation: 7483
TextArea was designed to grow by the size of its content, you can add limit to that:
TextArea txtLabel = new TextArea((String) data[row][col]);
txtLabel.setUIID("login_title");
txtLabel.setEditable(false);
txtLabel.setRows(2);
txtLabel.setGrowLimit(2);
txtLabel.setScrollVisible(false);
Upvotes: 1