Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » TreeViewer & Columns number(too many column!)
TreeViewer & Columns number [message #1671827] Fri, 13 March 2015 19:30 Go to next message
Kasper M.Friend
Messages: 15
Registered: September 2014
Junior Member
Hi all,
the code below show my tree viewer with one column more (apparently not requested Mad ).
Indeed, it shows, correctly, the first two column "Column 1" and "Column 2" but one more empty 3rd column .... Crying or Very Sad

any idea/help from you expert?

personTab.setText("MY GREAT TAB");

Tree personTree = new Tree(parentTabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
personTree.setHeaderVisible(true);
TreeViewer treeViewer = new TreeViewer(personTree);

TreeColumn column1 = new TreeColumn(personTree, SWT.LEFT);
personTree.setLinesVisible(true);
column1.setAlignment(SWT.LEFT);
column1.setText("Column 1");
column1.setWidth(100);

TreeColumn column2 = new TreeColumn(personTree, SWT.RIGHT);
personTree.setLinesVisible(true);
column2.setAlignment(SWT.LEFT);
column2.setText("Column 2");
column2.setWidth(100);

personTab.setControl(treeViewer.getTree());
Re: TreeViewer & Columns number [message #1679466 is a reply to message #1671827] Mon, 16 March 2015 16:27 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 786
Registered: January 2012
Senior Member

You're mixing JFace and SWT: use JFace to create the columns. Rather than create SWT TableColumns, create JFace TableViewerColumns instead.

Brian.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: TreeViewer & Columns number [message #1679607 is a reply to message #1679466] Mon, 16 March 2015 17:38 Go to previous messageGo to next message
Kasper M.Friend
Messages: 15
Registered: September 2014
Junior Member
mmh ... right Shocked

refactored but with the same result Mad

		// tabFolder is a CTabFolder!
		CTabItem personTab = new CTabItem(commandsTabFolder, SWT.NONE);
		personTab.setText("MY GREAT TAB");

		TableViewer treeViewer = new TableViewer(commandsTabFolder);

		// first column is for the first name
		final TableViewerColumn viewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
		TableColumn column = viewerColumn.getColumn();
		column.setText("Name");
		column.setWidth(150);

		TableViewerColumn viewerColumn2 = new TableViewerColumn(treeViewer, SWT.NONE);
		column = viewerColumn2.getColumn();
		column.setText("Surname");
		column.setWidth(200);

		final Table table = treeViewer.getTable();
		table.setHeaderVisible(true);
		table.setLinesVisible(true);

		GridLayout layout = new GridLayout(2, true);
		commandsTabFolder.setLayout(layout);

		personTab.setControl(treeViewer.getTable());
Re: TreeViewer & Columns number [message #1684762 is a reply to message #1671827] Wed, 18 March 2015 15:13 Go to previous messageGo to next message
Thibault Le Ouay is currently offline Thibault Le OuayFriend
Messages: 23
Registered: October 2014
Junior Member
You should use the TableColumnLayout

        Composite innerComposite = new Composite(shell, SWT.NONE);
        TableColumnLayout tableColumLayout = new TableColumnLayout();
        innerComposite.setLayout(tableColumLayout);
        TableViewer treeViewer = new TableViewer(innerComposite);

        // first column is for the first name
        final TableViewerColumn viewerColumn1 = new TableViewerColumn(treeViewer, SWT.NONE);
        TableColumn column = viewerColumn1.getColumn();
        column.setText("Name");

        tableColumLayout.setColumnData(viewerColumn1.getColumn(), new ColumnWeightData(50));
        TableViewerColumn viewerColumn2 = new TableViewerColumn(treeViewer, SWT.NONE);
        column = viewerColumn2.getColumn();
        column.setText("Surname");
        tableColumLayout.setColumnData(viewerColumn2.getColumn(), new ColumnWeightData(50));


        final Table table = treeViewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);



Play with the weight data

Enjoy !

HTH

Thibault
Re: TreeViewer & Columns number [message #1686779 is a reply to message #1684762] Thu, 19 March 2015 10:48 Go to previous message
Kasper M.Friend
Messages: 15
Registered: September 2014
Junior Member
thanks Thibault Smile
yes, I did it ... but was not working too .... so I realized that I was using CTabItem Sad
by replacing it with TabItem I got it working

Bye
Kasper
Previous Topic:Syncing different Parts together
Next Topic:TreeViewer with ILazyTreeContentProvider
Goto Forum:
  


Current Time: Thu Nov 15 05:51:06 GMT 2018

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

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

Back to the top