Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Bolding selected TreeItem (answered)
Bolding selected TreeItem (answered) [message #1063890] Fri, 14 June 2013 15:26 Go to next message
Eclipse UserFriend
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 07:19] by Moderator

Re: Bolding selected TreeItem [message #1064351 is a reply to message #1063890] Tue, 18 June 2013 16:26 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 16:31:35 EDT 2025

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

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

Back to the top