Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Bolding selected TreeItem (answered)
Bolding selected TreeItem (answered) [message #1063890] Fri, 14 June 2013 19:26 Go to next message
valentin Mising name is currently offline valentin Mising nameFriend
Messages: 36
Registered: December 2011
Member
I have a

fTree = new Tree(treeComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
fTree.setLinesVisible(true);

TreeColumn column1 = new TreeColumn(fTree, SWT.LEFT);
column1.setText("Signal");
treeColumnLayout.setColumnData(column1, new ColumnWeightData(50, 150, true));

TreeColumn column2 = new TreeColumn(fTree, SWT.LEFT);
column2.setText("Value");
treeColumnLayout.setColumnData(column2, new ColumnWeightData(50, 4096, true));


How do I make text bold in both columns when item is selected (or highlight its backgournd color)?

Ok, I have succeeded with this code,


public Font setBold(Font font, boolean bold) {
	FontData[] fD = font.getFontData();
	fD[0].setStyle(bold ? SWT.BOLD : 0); 
	return new Font(fDisplay,fD[0]);
}

fTree.addSelectionListener(new SelectionAdapter() {
			
	void bold(TreeItem[] items) {
		for (TreeItem item : items) {
			boolean bold = Arrays.asList(fTree.getSelection()).contains(item);
			item.setFont(setBold(item.getFont(), bold));
			item.setBackground(bold ? fWhite : fBlack);
			bold(item.getItems());
		}
	}
			
	public void widgetSelected(SelectionEvent e) {
		super.widgetSelected(e);
		startCanvasPaintJob();
		bold(fTree.getItems());
	}


Row selection was great with SWT.FULL_SELECTION tree style.

[Updated on: Sun, 16 June 2013 11:19]

Report message to a moderator

Re: Bolding selected TreeItem [message #1064351 is a reply to message #1063890] Tue, 18 June 2013 20:26 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
You can set an item's font to a bold one with TreeItem.setFont(Font), or
TreeItem.setFont(int, Font) for an individual "cell". Similarly, use
setBackground() to change its background color (or if you want to do
something more distinct you can custom draw the item's background as
described in
http://www.eclipse.org/articles/article.php?file=Article-CustomDrawingTableAndTreeItems/index.html
).

Grant


On 6/14/2013 3:26 PM, valentin Mising name wrote:
> I have a
>
> fTree = new Tree(treeComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
> fTree.setLinesVisible(true);
>
> TreeColumn column1 = new TreeColumn(fTree, SWT.LEFT);
> column1.setText("Signal");
> treeColumnLayout.setColumnData(column1, new ColumnWeightData(50, 150,
> true));
>
> TreeColumn column2 = new TreeColumn(fTree, SWT.LEFT);
> column2.setText("Value");
> treeColumnLayout.setColumnData(column2, new ColumnWeightData(50, 4096,
> true));
>
> How do I make text bold in both columns when item is selected (or
> highlight its backgournd color)?
Previous Topic:[Word Automation] How to get an item from a collection?
Next Topic:Getting the 'Application' property of a Word OleClientSite returns null
Goto Forum:
  


Current Time: Sun Dec 21 05:34:13 GMT 2014

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

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