Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » KTABLE Too Slow - Any Alternative?
KTABLE Too Slow - Any Alternative? [message #465394] Mon, 12 December 2005 16:23 Go to next message
steve lane is currently offline steve laneFriend
Messages: 24
Registered: July 2009
Junior Member
Hi, we needed to add the ability to freeze the first column in our SWT
app. Sadly SWT doesnt appear to support this so i used KTable. I like
KTable - its more like SWING model. But, its slow and clunky, especially
if you use rendering to colour the columns. Is there any alternative to
KTable or any way of making SWT achieve this - i find SWT's table's very
poor in comparison to Swing.

thanks,

steve.
Re: KTABLE Too Slow - Any Alternative? [message #465395 is a reply to message #465394] Mon, 12 December 2005 16:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

Hi Steve,

just curious why you thing KTable is slow: on what OS and hardware are
you running? How do you render you cells?

Usually it is a slow model or renderer implementation that causes a slow
KTable. I might not be the most objective judge, but for me KTable is a
very smooth and "quick" widget...

Regards,
Friederich


steve lane wrote:
>
> Hi, we needed to add the ability to freeze the first column in our SWT
> app. Sadly SWT doesnt appear to support this so i used KTable. I like
> KTable - its more like SWING model. But, its slow and clunky,
> especially if you use rendering to colour the columns. Is there any
> alternative to KTable or any way of making SWT achieve this - i find
> SWT's table's very poor in comparison to Swing.
>
> thanks,
>
> steve.
>


--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel +49 241 9979356
Fax +49 221 726670
www.kupzog.de/fkmk
Re: KTABLE Too Slow - Any Alternative? [message #465396 is a reply to message #465395] Mon, 12 December 2005 17:23 Go to previous messageGo to next message
steve lane is currently offline steve laneFriend
Messages: 24
Registered: July 2009
Junior Member
Thanks Friederich,

Perhaps i am using it wrong ! I have a table that is quite wide and to
make the table more readable, rows are grouped in 3's by changing the
background colour of the columns from a lighter gray to a darker gray.
When the table is scrolled with the scrollbar, it is visibly very slow at
re-drawing (i am only displaying 10 rows at a time). Im running on XP
with jdk1.4.2.

What i am doing code wise is this:

class KTableTextModel extends KTableDefaultModel {
private final TextCellRenderer m_textRenderer =
new TextCellRenderer(TextCellRenderer.INDICATION_FOCUS_ROW);
..
..
public Object doGetContentAt(int col, int row) {

if (col > 2) {
if ((((col-3) / 3) % 2) == 0) {
m_textRenderer.setBackground(AppConstants.getInstance().gray 1);
}
else {
m_textRenderer.setBackground(AppConstants.getInstance().gray 2);
}
}
.....
.....
}
..
..

thanks,

steve.
Re: KTABLE Too Slow - Any Alternative? [message #465413 is a reply to message #465396] Mon, 12 December 2005 22:11 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

Hi Steve,

you should put the m_textRenderer.setBackground() call into
doGetCellRenderer(int, int). But I cannot imagine that
this causes the problem. Anyway try it...

What is this AppConstants.getInstance().gray1 stuff? Maybe try to set up
your colors in a couple of local Color variables. Is the table quicker
without color changes?

If not, from where do you get the actual content?

Regards,
Friederich


steve lane wrote:
>
> Thanks Friederich,
>
> Perhaps i am using it wrong ! I have a table that is quite wide and to
> make the table more readable, rows are grouped in 3's by changing the
> background colour of the columns from a lighter gray to a darker gray.
> When the table is scrolled with the scrollbar, it is visibly very slow
> at re-drawing (i am only displaying 10 rows at a time). Im running on
> XP with jdk1.4.2.
>
> What i am doing code wise is this:
>
> class KTableTextModel extends KTableDefaultModel {
> private final TextCellRenderer m_textRenderer = new
> TextCellRenderer(TextCellRenderer.INDICATION_FOCUS_ROW);
> .
> .
> public Object doGetContentAt(int col, int row) {
> if (col > 2) {
> if ((((col-3) / 3) % 2) == 0) {
> m_textRenderer.setBackground(AppConstants.getInstance().gray 1);
> }
> else {
> m_textRenderer.setBackground(AppConstants.getInstance().gray 2);
> }
> }
> .....
> .....
> }
> .
> .
>
> thanks,
>
> steve.
>


--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel +49 241 9979356
Fax +49 221 726670
www.kupzog.de/fkmk
Re: KTABLE Too Slow - Any Alternative? [message #465415 is a reply to message #465396] Mon, 12 December 2005 22:46 Go to previous messageGo to next message
Lorenz Maierhofer is currently offline Lorenz MaierhoferFriend
Messages: 88
Registered: July 2009
Member
Hi,

I am fairly sure that setting/drawing a color cannot make any
significant difference.

As friedrich wrote:
Typically the table becomes slow when you have some expensive operations
in any of the model methods. Most of them are called quite heavily on
redraw, so you might use local caches in your table model.

Just to be sure:
The default KTable distribution contains some examples.
Are they slow as well?


Lorenz

steve lane wrote:
>
> Thanks Friederich,
>
> Perhaps i am using it wrong ! I have a table that is quite wide and to
> make the table more readable, rows are grouped in 3's by changing the
> background colour of the columns from a lighter gray to a darker gray.
> When the table is scrolled with the scrollbar, it is visibly very slow
> at re-drawing (i am only displaying 10 rows at a time). Im running on
> XP with jdk1.4.2.
>
> What i am doing code wise is this:
>
> class KTableTextModel extends KTableDefaultModel {
> private final TextCellRenderer m_textRenderer = new
> TextCellRenderer(TextCellRenderer.INDICATION_FOCUS_ROW);
> .
> .
> public Object doGetContentAt(int col, int row) {
> if (col > 2) {
> if ((((col-3) / 3) % 2) == 0) {
> m_textRenderer.setBackground(AppConstants.getInstance().gray 1);
> }
> else {
> m_textRenderer.setBackground(AppConstants.getInstance().gray 2);
> }
> }
> .....
> .....
> }
> .
> .
>
> thanks,
>
> steve.
>
Re: KTABLE Too Slow - Any Alternative? [message #465430 is a reply to message #465413] Tue, 13 December 2005 10:03 Go to previous messageGo to next message
steve lane is currently offline steve laneFriend
Messages: 24
Registered: July 2009
Junior Member
Hi Friederich,

Thanks for your reply. I am new to KTable but am liking it more and more.
You response has helped me understand it considerably better and i think
you are right that its my fairly heavy rendering code causing the issue
which i need to address. Actually moving the code into the
doGetCellRenderer did make quite a difference as well.

On a slightly seperate ktable issue though, i understand it looks
different to SWT as its not native widgets, but is it possible to make the
header row look a little nicer ? The header row just comes up as a flat
grey look - is there some way you can make it look slightly bevelled as
with the SWT ones??

thanks,

steve.
Re: KTABLE Too Slow - Any Alternative? [message #465432 is a reply to message #465430] Tue, 13 December 2005 10:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: friederich.kupzog.de

steve lane wrote:
> On a slightly seperate ktable issue though, i understand it looks
> different to SWT as its not native widgets, but is it possible to make
> the header row look a little nicer ? The header row just comes up as a
> flat grey look - is there some way you can make it look slightly
> bevelled as with the SWT ones??

Hi Steve,

the following code draws WinXP-like table headers. You can implement
your own KTableCellRenderer and use this code. The code is taken from a
propriety renderer from a 1.x KTable implementation, therefore I am
unfortunately not able to send you the complete renderer class.

public static void drawHeader(GC gc, Rectangle rect, String text)
{
gc.setBackground(ResourceManager.getColor(SWT.COLOR_WIDGET_B ACKGROUND));
gc.fillRectangle(rect);

gc.setForeground(ResourceManager.getColor(SWT.COLOR_WIDGET_H IGHLIGHT_SHADOW));
// obere Linie
gc.drawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y);

// Hellerer Trenner
gc.drawLine(rect.x+rect.width-2, rect.y+2, rect.x+rect.width-2,
rect.y+rect.height-4);

gc.setForeground(ResourceManager.getColor(192,192,192));
// leichtere Schattenlinien oben
gc.drawLine(rect.x, rect.y+rect.height-2, rect.x+rect.width-1,
rect.y+rect.height-2);

// dunklerer Trenner
gc.drawLine(rect.x+rect.width-3, rect.y+2, rect.x+rect.width-3,
rect.y+rect.height-4);

gc.setForeground(ResourceManager.getColor(SWT.COLOR_WIDGET_N ORMAL_SHADOW));
// Leichte Schattenlinie unten
gc.drawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width-1,
rect.y+rect.height-1);

if (text == null) text = "";
Point textSize = getCachedStringExtent(gc, text);
boolean addPoint = false;
while ((text.length() > 0) && (textSize.x >= rect.width-4)) {
text = text.substring(0, text.length() - 1);
textSize = getCachedStringExtent(gc, text + "...");
addPoint = true;
}
if (addPoint) text = text + "...";
textSize = getCachedStringExtent(gc, text);
if (textSize.x >= rect.width-4) {
text = "";
textSize = getCachedStringExtent(gc, text);
}

gc.setForeground(ResourceManager.getColor(SWT.COLOR_WIDGET_F OREGROUND));
gc.drawText(text, rect.x+3, rect.y+3);
}

public static void drawInvertedHeader(GC gc, Rectangle rect, String text)
{
gc.setBackground(ResourceManager.getColor(220,220,212));
gc.fillRectangle(rect);

gc.setForeground(ResourceManager.getColor(250,250,240));
gc.drawLine(rect.x+1, rect.y+rect.height-2, rect.x+rect.width-1,
rect.y+rect.height-2);
gc.drawLine(rect.x+rect.width-2, rect.y+1, rect.x+rect.width-2,
rect.y+rect.height-3);

gc.setForeground(ResourceManager.getColor(SWT.COLOR_WIDGET_N ORMAL_SHADOW));
gc.drawRectangle(rect.x, rect.y, rect.width-1, rect.height-1);

if (text == null) text = "";
Point textSize = getCachedStringExtent(gc, text);
boolean addPoint = false;
while ((text.length() > 0) && (textSize.x >= rect.width-4)) {
text = text.substring(0, text.length() - 1);
textSize = getCachedStringExtent(gc, text + "...");
addPoint = true;
}
if (addPoint) text = text + "...";
textSize = getCachedStringExtent(gc, text);
if (textSize.x >= rect.width-4) {
text = "";
textSize = getCachedStringExtent(gc, text);
}

gc.setForeground(ResourceManager.getColor(SWT.COLOR_WIDGET_F OREGROUND));
gc.drawText(text, rect.x+4, rect.y+4);
}





--
Friederich Kupzog
Elektronik & Software
Neusser Str. 5-7
50670 Köln
Tel +49 241 9979356
Fax +49 221 726670
www.kupzog.de/fkmk
Re: KTABLE Too Slow - Any Alternative? [message #465438 is a reply to message #465432] Tue, 13 December 2005 12:38 Go to previous message
steve lane is currently offline steve laneFriend
Messages: 24
Registered: July 2009
Junior Member
Thanks friederich. I am converted, KTable rocks !!!
Previous Topic:HTML RTF Editor
Next Topic:Bug in SWT
Goto Forum:
  


Current Time: Thu Apr 25 16:38:43 GMT 2024

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

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

Back to the top