954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SWT table

hi!

I have 2 columns SWT table.
but when I insert data (from Mysql query), it appear only in the first column.
for make it show in the second, I have to change the size of the column and then the data appear.

so right now, after every query, I change the column width automatically, and it works.

anyway, I wanna know why does it happen? and get the real solution for that problem.

-Nate

neti1987
Newbie Poster
24 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

It happens because changing the size of the column indirectly causes the layout() method to be called on your widget. In order to dynamically insert data into the table, you could just call layout() on the table after you add the data. Then you won't need to reset the column size.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

Thanks!

could you show me exactly what I should write?

will it make all the column appear?

right now, every time i change the column width, only the rows which I can see, are updated (the table could be scrolled).

thanks again!
-Nate

neti1987
Newbie Poster
24 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 
It happens because changing the size of the column indirectly causes the layout() method to be called on your widget. In order to dynamically insert data into the table, you could just call layout() on the table after you add the data. Then you won't need to reset the column size.


It's doesn't work for me...

could u think about something else?

Thanks,
Nate

neti1987
Newbie Poster
24 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Can you show me what you tried doing? Just the relevant parts, like setting the table data then attempting to redisplay it. You might also try calling the layout() method on the Display that contains the table. Basically calling it on the outer component might work. I forget the correct terminology and TBH I don't have Eclipse installed right now due to a hard drive failure and subsequent wipe, so I'm not in a position to test anything.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 
Can you show me what you tried doing? Just the relevant parts, like setting the table data then attempting to redisplay it. You might also try calling the layout() method on the Display that contains the table. Basically calling it on the outer component might work. I forget the correct terminology and TBH I don't have Eclipse installed right now due to a hard drive failure and subsequent wipe, so I'm not in a position to test anything.

the window which contain the table is a composite.
in my project, there are some composites in tabs.

here is the code which update the table:

public LinkedList<String> results;

	private void displayResults() {
		if (results == null || results.size() < 1) { // if there wasn't found any results.
			// OPTION - prompt a message box - "NO RESULTS".
			return;
		}
		String sep = FileSystems.getDefault().getSeparator(); // get the system path seperator.
		String s;
		int i;
		Iterator<String> it = results.iterator();
		while (it.hasNext()) {
			// decompose the string to file address and name:
			s = it.next();
			i = s.lastIndexOf(sep);
			TableItem item = new TableItem (resultsTable, SWT.NONE);
			if (i > 0) { // if there is seperator and not as first char:
				item.setText (new String [] {s.substring(i+1), s.substring(0, i)});
			} else {
				item.setText (new String [] {s, ""});
			}
		}
		
	}
neti1987
Newbie Poster
24 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Well that doesn't show where you called the layout method and what you called it on. See this article which reiterates what I explained before.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: