Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Table(Modifying and accessing a SWT Table)
icon9.gif  SWT Table [message #526161] Fri, 09 April 2010 03:16 Go to next message
Rainer is currently offline RainerFriend
Messages: 3
Registered: April 2010
Junior Member
Hello,

I cannot get it right, to modify and access specific colums, rows or cells within the SWT table.

I am making a SWT table with the following code:
	
String[] titles = {Mon, Tue,  Wed, Thu, Fri, Sat, Sun};	
		for (int i=0; i<titles.length; i++) {
			TableColumn column = new TableColumn (table, SWT.NONE);
			column.setText (titles [i]);
		}	
		for (int i=0; i<titles.length; i++) {
			table.getColumn (i).pack ();
		}


With the following code I want to delete the table and rewrite the cells of a specific column, which works for the first column of the table:
int countInt = 0;
		table.removeAll();
		for (Entry e : EntryList) {
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText(e.EntryNameString);
			countInt++;
		}


But how to access the cells of the second column?

Why does it not work like Excel with columns, rows and cells?

I only see the first column and the items of it.
Which are per column or row, how are they spread among the table?
Why does the SWT table not have rows?
Embarrassed

I googled the whole night long and the eclipse documentation is not useful either. Confused

Please help! Crying or Very Sad
Re: SWT Table [message #526167 is a reply to message #526161] Fri, 09 April 2010 05:49 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
Rainer wrote:
> Why does it not work like Excel with columns, rows and cells?
> Which are per column or row, how are they spread among the table?
> Why does the SWT table not have rows?
I'm not sure exactly what you are trying to do. However, if you need to
modify the text of multiple columns of same row, then you could use
either of these APIs :
item.setText (columnIndex, String)
item.setText (String[])

where 'item' corresponds to a particular row, that can be obtained
through table.getItem(rowIndex)

So, SWT maintains multiple columns per row for every table - which is
what you are looking for. So, everything is accessible through the
available APIs.
If I am missing something here, please let me know whether you are
looking for something else.
icon5.gif  Re: SWT Table [message #529721 is a reply to message #526167] Mon, 26 April 2010 23:00 Go to previous messageGo to next message
Rainer is currently offline RainerFriend
Messages: 3
Registered: April 2010
Junior Member
I now got what I want to do clearer:
I want to iterate through the first column and sub-iterate throught each of it's rows.

The SWT Table:
http://img408.imageshack.us/img408/7197/javaswttableiteration01.jpg
( http://img408.imageshack.us/img408/7197/javaswttableiteratio n01.jpg)

The iteration:
http://img186.imageshack.us/img186/4316/javaswttableiteration02.jpg
( http://img186.imageshack.us/img186/4316/javaswttableiteratio n02.jpg)

All I got until now: Embarrassed
http://img175.imageshack.us/img175/2121/javaswttableiteration03.jpg
( http://img175.imageshack.us/img175/2121/javaswttableiteratio n03.jpg)

I am just using
new Table (parentTemp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION)

Any ideas, please? Rolling Eyes

I put the links in plain text, if the image embedment does not work correctly. I see them with the newest Firefox... Cool
Just strange that the links seem OK but there is a space between the o and the n that should not be there... Confused

[Updated on: Tue, 27 April 2010 21:46]

Report message to a moderator

Re: SWT Table [message #530006 is a reply to message #529721] Wed, 28 April 2010 06:19 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 27.04.2010 01:00, Rainer wrote:
> I now got what I want to do clearer:
> I want to iterate through the first column and sub-iterate throught each
> of it's rows.
>
> The SWT Table:
>
>
> The iteration:
>
>
> All I got until now: :blush:
>
> I am just using
> new Table (parentTemp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION)
> Any ideas, please? :roll:
> If image links will get broken maybe sometime just post a corresponding
> reply or pm me. :d

[Images and links cannot be recognized on Mozilla Thunderbird].

I don't understand why you removed all table items in your initial
posting. You don't need that for a proper iteration. Praveen did
already describe what you should do. Here a complete snippet (A
variation of SWT snippet 38) that shows how to realize that (I use
Java 1.5 features in the code):

public class Snippet38Iterate {

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Table table = new Table(shell, SWT.MULTI | SWT.BORDER
| SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200;
table.setLayoutData(data);
String[] titles = { "A", "B", "C", "D", "E", "F", "G" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(titles[i]);
}
final int rows = 10;
// Just generate all rows:
for (int i = 0; i < rows; i++) {
new TableItem(table, SWT.NONE);
}
final int cols = table.getColumnCount();
// Iterate through all items from top to bottom
// and from left to right:
for (int i = 0; i < rows; i++) {
TableItem item = table.getItem(i);
for (int j = 0; j < cols; ++j) {
item.setText(j, String.format("[%s, %s]", i + 1, j + 1));
}
}
for (int i = 0; i < titles.length; i++) {
table.getColumn(i).pack();
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

}

HTH & Greetings from Bremen,

Daniel Krügler
Re: SWT Table [message #532190 is a reply to message #530006] Fri, 07 May 2010 13:14 Go to previous message
Rainer is currently offline RainerFriend
Messages: 3
Registered: April 2010
Junior Member
Thanks for your help! Very Happy

I now got it.

My appropriate code segment now looks like this:

			int intTemp01 = table.getItemCount();
			int intTemp02 = table.getColumnCount();
			// Iterate through all items from top to bottom
			// and from left to right:
			for (int i = 0; i < intTemp01; i++) {
			TableItem item = table.getItem(i);
				for (int j = 1; j < intTemp02; ++j) {
					item.setText(j, String.format("[%s, %s]", i + 1, j + 1));
				}
			}	


HTH & Greetings from the border of South Germany,

Rainer
Previous Topic:Video support using SWT
Next Topic:Programmatic web page image creation using SWT
Goto Forum:
  


Current Time: Thu Apr 25 23:10:24 GMT 2024

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

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

Back to the top