|
|
Re: Wrong cell color return in Linux [message #530126 is a reply to message #530117] |
Wed, 28 April 2010 14:53 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
To clarify, there isn't a simple way to determine this. The snippet below
demonstrates getting the colour that's under a hovered pointer. If you want
to get the white/grey colour of a TableItem you can do something similar by
getting the colour of its top-left corner pixel where the text or image
should not reach. The only case this doesn't help with is if an item is
selected, in which case it will always evaluate to "not white".
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.NONE);
table.setLinesVisible(true);
for (int i = 0; i < 9; i++) {
new TableItem(table, SWT.NONE).setText("item " + i);
}
table.addListener(SWT.MouseHover, new Listener() {
public void handleEvent(Event event) {
GC gc = new GC(table);
Image image = new Image(display, 1, 1);
gc.copyArea(image, event.x, event.y);
if (image.getImageData().getPixel(0, 0) == 0xFFFFFF) {
System.out.println("white");
} else {
System.out.println("not white");
}
image.dispose();
gc.dispose();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
HTH,
Grant
"Grant Gayed" <grant_gayed@ca.ibm.com> wrote in message
news:hr9gni$78u$1@build.eclipse.org...
> Hi, sorry for the late reply,
>
> The alternating line colours are gtk's native implementation of
> Table.setLinesVisible(true). These are not considered to be item
background
> colours, which is why you're always getting a return value of white. In
> your scenario there isn't a way to determine whether a row's background is
> coloured or not as a result of Table.setLinesVisible(true).
>
> Grant
>
>
> "Vincent" <vincent.wen@ottoint.com> wrote in message
> news:hq61h0$m65$1@build.eclipse.org...
> > In Linux, table rows showing in alternating colors. I do listen to a
> MouseMove event and want to get the background color of a cell using
> item.getBackground(i) . But, I fail to get a correct "grey" color when I
> pointing to a "grey" row. What it return is always white. Anyone has idea
> about it?
>
>
|
|
|
Re: Wrong cell color return in Linux [message #530532 is a reply to message #530126] |
Fri, 30 April 2010 01:38 |
Vincent Messages: 6 Registered: April 2010 |
Junior Member |
|
|
Hi Grant Gayed,
Really thanks for your reply. I think I can take your way in some cases in my application.
Moreover, though you said alternating line colors of table is native gtk's implementation, I think it's quite confusing that the api of item.getBackground(i) don't return the "actual" color of a row. Just want to hear if you have any comments.
Again, thanks for your helpfulness.
Vincent
[Updated on: Fri, 30 April 2010 01:39] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03334 seconds