Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two rows get added while inserting single row  RSS feed

 
Mukund Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Experts,

I am facing some issues while adding single row in Jface table. one for lable provider and one for actual data, the code snippet is -


private void initUI( Composite parent )
{
shell = parent.getShell();
GridLayout layout = new GridLayout( 2, true );
parent.setLayout( layout );

tableViewer = new TableViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER );

createTableViewerColumn( titles[0], bounds[0], 0 );
.....................

table = tableViewer.getTable();
GridData gd_table = new GridData( SWT.FILL, SWT.FILL, false, false, 1, 4 );
gd_table.verticalIndent = 5;
table.setLayoutData( gd_table );
table.setHeaderVisible( true );
table.setLinesVisible( true );

tableViewer.setContentProvider( new ArrayContentProvider() );
tableViewer.setLabelProvider( new LabelProvider() );
............

// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.verticalSpan = 5;
// gridData.grabExcessHorizontalSpace = true;
// gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
tableViewer.getControl().setLayoutData( gridData );
}


and the code to add the row is -

TableItem item = new TableItem( table, 1 );
item.setText( new String[] {pmmRecipe.getPartTemplateID(), pmmRecipe.getPartID(), pmmRecipe.getPartItemID(),
pmmRecipe.getPartItemRevType()} );

// tableViewer.insert( item, 0 );
tableViewer.add( item );

Is anything I have missed here?
Please provide the resolution for it..

Thanks,
Mukund
 
Mukund Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replacing createTableViewerColumn( titles[0], bounds[0], 0 ); with below code, it works-

col = createTableViewerColumn( titles[0], bounds[0], 0 );
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Person p = (Person) element;
return p.getLastName();
}
});
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!