Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TableColumnLayout problem on mac os
TableColumnLayout problem on mac os [message #1052581] Tue, 30 April 2013 09:05
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

I'm using Eclipse Indigo SR2.

I wanted to have a table viewer with two columns: a column with a fixed size and a column which has the same with as its largest cell (so you don't have to resize the column to fully see its content). If the column is too large and goes outside the range of the TableViewer, then an horizontal scroll bar appears on the table viewer.

I have the following piece of code which works fine on windows but doesn't work on mac: the second column is always a couple of pixels wide and thus you can only see the 2 first characters followed by "..."

(The code is taken from a custom view)
	class ViewContentProvider implements IStructuredContentProvider {
		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
		}

		public void dispose() {
		}

		public Object[] getElements(Object parent) {
			if (parent instanceof Object[]) {
				return (Object[]) parent;
			}
			return new Object[0];
		}
	}

	class ViewLabelProvider extends ColumnLabelProvider {

		private int columnIndex;

		public ViewLabelProvider(int colIndex) {
			columnIndex = colIndex;
		}

		@Override
		public String getText(Object element) {
			if (columnIndex == 0) {
				return "";
			}
			return super.getText(element);
		}
	}

	public void createPartControl(Composite parent) {
		TableColumnLayout tableLayout = new TableColumnLayout();
		parent.setLayout(tableLayout);

		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL);
		viewer.setContentProvider(new ViewContentProvider());
		viewer.setLabelProvider(new ViewLabelProvider(0));
		// Provide the input to the ContentProvider
		viewer.setInput(new String[] { "One", "Two",
				"A loooooooooooooooooooooooooooooooooooooooooooooooooooooong string" });

		createColumns(viewer, tableLayout);
		refreshViewer();
	}


	private void createColumns(TableViewer viewer, TableColumnLayout tableLayout) {
		TableViewerColumn firstColumn = new TableViewerColumn(viewer, SWT.FILL);
		firstColumn.getColumn().setResizable(false);
		ViewLabelProvider labelProvider = new ViewLabelProvider(0);
		firstColumn.setLabelProvider(labelProvider);

		TableViewerColumn secondColumn = new TableViewerColumn(viewer, SWT.FILL);
		secondColumn.getColumn().setResizable(false);
		labelProvider = new ViewLabelProvider(1);
		secondColumn.setLabelProvider(labelProvider);

		tableLayout.setColumnData(firstColumn.getColumn(),
				new ColumnWeightData(0, 22));
		tableLayout.setColumnData(secondColumn.getColumn(),
				new ColumnWeightData(100, 100));
		viewer.getTable().setLinesVisible(false);
		viewer.getTable().setHeaderVisible(false);
	}

	protected void refreshViewer() {
		viewer.refresh();
		Table table = viewer.getTable();
		for (TableColumn column : table.getColumns()) {
			column.pack();
		}
	}


To make it easier to test, I attached a sample project which creates a sample view a TableViewer showing the problem.

Thanks,
Cédric
Previous Topic:TableViewer evaluation
Next Topic:TextViewerUndoManager
Goto Forum:
  


Current Time: Thu Apr 25 05:43:49 GMT 2024

Powered by FUDForum. Page generated in 0.02946 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top