Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » hiding selection in SWT table
hiding selection in SWT table [message #444691] Wed, 20 October 2004 15:13 Go to next message
Yves Harms is currently offline Yves HarmsFriend
Messages: 80
Registered: July 2009
Member
Hi,
how can i hide the selection (not the row or cell) in a table ?
Deselect() doesnt work as expected, my example should result in showing
no selection at all.
(I want to hide the selection made by swt and code my own that simply
colors the clicked cells.)

Thanks in advance,
Yves


> package com.comosoft.rcp.examples;
>
> /*
> * Table example snippet: color cells and rows in table
> *
> */
> import org.eclipse.swt.*;
> import org.eclipse.swt.graphics.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.widgets.*;
>
> /**
> * @author yharms
> *
> * TODO To change the template for this generated type comment go to
> * Window - Preferences - Java - Code Style - Code Templates
> */
> public class TableCellMultiSelectionSnippet {
>
> /**
> * <code>pressedKey</code> : the key currently pressed down, 0 if currently no key is presed down
> */
>
> public void createPartControl(Composite parent){
> final Table table = new Table(parent, SWT.BORDER|SWT.SINGLE);
> table.setHeaderVisible(true);
>
> String[] columnNames = {"a","b","c"};
> TableColumn col1 = new TableColumn(table, SWT.NONE);
> TableColumn col2 = new TableColumn(table, SWT.NONE);
> TableColumn col3 = new TableColumn(table, SWT.NONE);
> col1.setText(columnNames[0]);
> col2.setText(columnNames[1]);
> col3.setText(columnNames[2]);
> col1.pack();
> col2.pack();
> col3.pack();
>
>
> TableItem item = new TableItem(table, SWT.NONE);
> item.setText(new String[] {"white fore/blue back","normal","white fore/red back"});
>
> item = new TableItem(table, SWT.NONE);
> item.setText(new String[] {"white fore/blue back","normal","white fore/red back"});
>
> table.addListener (SWT.Selection, new Listener () {
> public void handleEvent (Event event) {
> Rectangle clientArea = table.getClientArea ();
> Point pt = new Point (event.x, event.y);
> int index = table.getTopIndex ();
> while (index < table.getItemCount ()) {
> boolean visible = false;
> TableItem item = table.getItem (index);
> for (int i=0; i < table.getColumnCount(); i++) {
> Rectangle rect = item.getBounds (i);
> if (rect.contains (pt)) {
>
> table.deselect(index);
> table.setFocus();
> //table.select(0);
> System.out.println("hhg");
> }
> if (!visible && rect.intersects (clientArea)) {
> visible = true;
> }
> }
> if (!visible) return;
> index++;
> }
> }
> });
> }
>
>
> public static void main(String[] args) {
> Display display = new Display();
> TableCellColorSnippet app = new TableCellColorSnippet();
>
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> app.createPartControl(shell);
>
> shell.pack();
> shell.open();
>
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
>
Re: hiding selection in SWT table [message #444705 is a reply to message #444691] Thu, 21 October 2004 08:12 Go to previous message
Yves Harms is currently offline Yves HarmsFriend
Messages: 80
Registered: July 2009
Member
I have figured out the bug:
replace
table.addListener (SWT.Selection, new Listener () {
with
table.addListener (SWT.MouseDown, new Listener () {


Yves Harms wrote:
> Hi,
> how can i hide the selection (not the row or cell) in a table ?
> Deselect() doesnt work as expected, my example should result in showing
> no selection at all.
> (I want to hide the selection made by swt and code my own that simply
> colors the clicked cells.)
>
> Thanks in advance,
> Yves
>
>
>> package com.comosoft.rcp.examples;
>> /*
>> * Table example snippet: color cells and rows in table
>> *
>> */
>> import org.eclipse.swt.*;
>> import org.eclipse.swt.graphics.*;
>> import org.eclipse.swt.layout.*;
>> import org.eclipse.swt.widgets.*;
>>
>> /**
>> * @author yharms
>> *
>> * TODO To change the template for this generated type comment go to
>> * Window - Preferences - Java - Code Style - Code Templates
>> */
>> public class TableCellMultiSelectionSnippet {
>>
>> /**
>> * <code>pressedKey</code> : the key currently pressed down, 0
>> if currently no key is presed down
>> */
>>
>> public void createPartControl(Composite parent){
>> final Table table = new Table(parent,
>> SWT.BORDER|SWT.SINGLE);
>> table.setHeaderVisible(true);
>>
>> String[] columnNames = {"a","b","c"};
>> TableColumn col1 = new TableColumn(table, SWT.NONE);
>> TableColumn col2 = new TableColumn(table, SWT.NONE);
>> TableColumn col3 = new TableColumn(table, SWT.NONE);
>> col1.setText(columnNames[0]);
>> col2.setText(columnNames[1]);
>> col3.setText(columnNames[2]);
>> col1.pack();
>> col2.pack();
>> col3.pack();
>>
>>
>> TableItem item = new TableItem(table, SWT.NONE);
>> item.setText(new String[] {"white fore/blue
>> back","normal","white fore/red back"});
>>
>> item = new TableItem(table, SWT.NONE);
>> item.setText(new String[] {"white fore/blue
>> back","normal","white fore/red back"});
>>
>> table.addListener (SWT.Selection, new Listener () {
>> public void handleEvent (Event event) {
>> Rectangle clientArea = table.getClientArea ();
>> Point pt = new Point (event.x, event.y);
>> int index = table.getTopIndex ();
>> while (index < table.getItemCount ()) {
>> boolean visible = false;
>> TableItem item = table.getItem (index);
>> for (int i=0; i < table.getColumnCount(); i++) {
>> Rectangle rect = item.getBounds (i);
>> if (rect.contains (pt))
>> {
>>
>> table.deselect(index);
>> table.setFocus();
>> //table.select(0);
>> System.out.println("hhg");
>> }
>> if (!visible && rect.intersects
>> (clientArea)) {
>> visible = true;
>> }
>> }
>> if (!visible) return;
>> index++;
>> }
>> }
>> });
>> }
>>
>>
>> public static void main(String[] args) {
>> Display display = new Display();
>> TableCellColorSnippet app = new TableCellColorSnippet();
>>
>> Shell shell = new Shell(display);
>> shell.setLayout(new FillLayout());
>> app.createPartControl(shell);
>>
>> shell.pack();
>> shell.open(); while (!shell.isDisposed()) {
>> if (!display.readAndDispatch())
>> display.sleep();
>> }
>> display.dispose();
>> }
>> }
>>
>
Previous Topic:Icon and title in Eclipse Help System
Next Topic:How do you alter the initial size of a Dialog?
Goto Forum:
  


Current Time: Thu Apr 18 10:44:58 GMT 2024

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

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

Back to the top