Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Table.setSortColumn sets column background to grey
| | |
Re: Table.setSortColumn sets column background to grey [message #753990 is a reply to message #753951] |
Mon, 31 October 2011 11:20 |
nimonic Messages: 6 Registered: October 2011 |
Junior Member |
|
|
I've tried the following:
If I set the table background to white there is no change.
If I set the table background to red the background changes to red.
If I set the table background to 'widgetBackground' the selected column changes to white and all other columns change to grey!
Could this be a bug?
My test code below:
import org.eclipse.swt.SWT;
public class SetSortColumnTest extends Shell {
private static Display display;
private Table table;
private Color white;
private Color red;
private Color widgetBackground;
/**
* Launch the application.
* @param args
*/
public static void main(String args[]) {
try {
display = Display.getDefault();
SetSortColumnTest shell = new SetSortColumnTest(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
* @param display
*/
public SetSortColumnTest(Display display) {
super(display, SWT.SHELL_TRIM);
createContents();
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(327, 308);
setLayout(new GridLayout(1, false));
ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
ToolItem tltmNormal = new ToolItem(toolBar, SWT.NONE);
tltmNormal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(null);
}
});
tltmNormal.setText("Normal");
ToolItem tltmWhite = new ToolItem(toolBar, SWT.NONE);
tltmWhite.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(white);
}
});
tltmWhite.setText("White");
ToolItem tltmRed = new ToolItem(toolBar, SWT.NONE);
tltmRed.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(red);
}
});
tltmRed.setText("Red");
ToolItem tltmWidgetBackground = new ToolItem(toolBar, SWT.NONE);
tltmWidgetBackground.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(widgetBackground);
}
});
tltmWidgetBackground.setText("Widget Background");
table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn tblclmnColumn1 = new TableColumn(table, SWT.NONE);
tblclmnColumn1.setWidth(100);
tblclmnColumn1.setText("Column 1");
TableColumn tblclmnColumn2 = new TableColumn(table, SWT.NONE);
tblclmnColumn2.setWidth(100);
tblclmnColumn2.setText("Column 2");
TableColumn tblclmnColumn3 = new TableColumn(table, SWT.NONE);
tblclmnColumn3.setWidth(100);
tblclmnColumn3.setText("Column3");
table.setSortColumn(tblclmnColumn2);
table.setSortDirection(SWT.UP);
white = display.getSystemColor(SWT.COLOR_WHITE);
red = display.getSystemColor(SWT.COLOR_RED);
widgetBackground = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
|
|
| |
Re: Table.setSortColumn sets column background to grey [message #754047 is a reply to message #754001] |
Mon, 31 October 2011 15:15 |
Marco Maccaferri Messages: 147 Registered: July 2009 |
Senior Member |
|
|
On 31/10/2011 12:38 Thomas Singer ha scritto:
> Tom Schindl wrote on Mon, 31 October 2011 03:02
>> did you try to set the item.setBackground(int,Color) which will overrule
>> the native coloring?
>
> No, I've did not tried, because I don't want to override the normal native
> coloring. I just want the sorting column background to be the same
platform
> specific coloring like the non-sorting columns.
A couple of tricks:
1. Add an SWT.EraseItem event listener to the Table and just fill with
the background color:
table.addListener(SWT.EraseItem, new Listener() {
@Override
public void handleEvent(Event event) {
event.gc.setBackground(((TableItem) event.item).getBackground());
event.gc.fillRectangle(event.getBounds());
}
});
2. Set the item background to a slightly different color than the
platform default, like if platform default is white (255,255,255) set it
to 254,255,255 or 254,254,254:
RGB rgb =
Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
if (rgb.red > 0) {
rgb.red--;
}
if (rgb.green > 0) {
rgb.green--;
}
if (rgb.blue > 0) {
rgb.blue--;
}
Color rowColor = new Color(Display.getDefault(), rgb);
Both of these disable the sort background, option 1 enables the owner
draw events so it may have some performance hits.
Hope this helps.
Regards,
Marco.
|
|
|
Re: Table.setSortColumn sets column background to grey [message #754098 is a reply to message #754047] |
Mon, 31 October 2011 18:35 |
nimonic Messages: 6 Registered: October 2011 |
Junior Member |
|
|
Thanks for your reply.
I'm not to keen on the first method if it has performance problems.
I've tried the second method but it didn't work. The selected column remained grey.
Test code below:
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class SetSortColumnTest extends Shell {
private static Display display;
private Table table;
private Color white;
private Color red;
private Color widgetBackground;
private Color rowColor;
private RGB rgb;
/**
* Launch the application.
* @param args
*/
public static void main(String args[]) {
try {
display = Display.getDefault();
SetSortColumnTest shell = new SetSortColumnTest(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
* @param display
*/
public SetSortColumnTest(Display display) {
super(display, SWT.SHELL_TRIM);
createContents();
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(327, 308);
setLayout(new GridLayout(1, false));
ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
ToolItem tltmNormal = new ToolItem(toolBar, SWT.NONE);
tltmNormal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(null);
}
});
tltmNormal.setText("Normal");
ToolItem tltmWhite = new ToolItem(toolBar, SWT.NONE);
tltmWhite.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(white);
}
});
tltmWhite.setText("White");
ToolItem tltmRed = new ToolItem(toolBar, SWT.NONE);
tltmRed.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(red);
}
});
tltmRed.setText("Red");
ToolItem tltmWidgetBackground = new ToolItem(toolBar, SWT.NONE);
tltmWidgetBackground.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(widgetBackground);
}
});
tltmWidgetBackground.setText("Widget Background");
ToolItem tltmNewRgb = new ToolItem(toolBar, SWT.NONE);
tltmNewRgb.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(rowColor);
}
});
tltmNewRgb.setText("New RGB");
table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn tblclmnColumn1 = new TableColumn(table, SWT.NONE);
tblclmnColumn1.setWidth(100);
tblclmnColumn1.setText("Column 1");
TableColumn tblclmnColumn2 = new TableColumn(table, SWT.NONE);
tblclmnColumn2.setWidth(100);
tblclmnColumn2.setText("Column 2");
TableColumn tblclmnColumn3 = new TableColumn(table, SWT.NONE);
tblclmnColumn3.setWidth(100);
tblclmnColumn3.setText("Column3");
table.setSortColumn(tblclmnColumn2);
table.setSortDirection(SWT.UP);
white = display.getSystemColor(SWT.COLOR_WHITE);
red = display.getSystemColor(SWT.COLOR_RED);
widgetBackground = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
rgb = Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
System.out.println("red: " + rgb.red);
System.out.println("green: " + rgb.green);
System.out.println("blue: " + rgb.blue);
rowColor = new Color(Display.getDefault(), 254, 254, 254);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
|
|
| |
Re: Table.setSortColumn sets column background to grey [message #754866 is a reply to message #754179] |
Fri, 04 November 2011 16:56 |
nimonic Messages: 6 Registered: October 2011 |
Junior Member |
|
|
Thanks again for your help but it's still not meeting my requirement.
Method one doesn't seem to work at all for me.
Method two only changes the background colour of table items so the rest of the selected column is still displayed in grey.
My code is below.
BTW does anyone know why the SWT table behaves like this? I can't recall ever seeing this behaviour in a windows application so I don't think it is native behaviour of a table widget.
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
public class SetSortColumnTest extends Shell {
private static Display display;
private Table table;
private Color white;
private Color red;
private Color widgetBackground;
private Color rowColor;
private RGB rgb;
/**
* Launch the application.
*
* @param args
*/
public static void main(String args[]) {
try {
display = Display.getDefault();
SetSortColumnTest shell = new SetSortColumnTest(display);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the shell.
*
* @param display
*/
public SetSortColumnTest(Display display) {
super(display, SWT.SHELL_TRIM);
createContents();
}
/**
* Create contents of the shell.
*/
protected void createContents() {
setText("SWT Application");
setSize(327, 308);
setLayout(new GridLayout(1, false));
ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
1, 1));
ToolItem tltmNormal = new ToolItem(toolBar, SWT.NONE);
tltmNormal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(null);
}
});
tltmNormal.setText("Normal");
ToolItem tltmWhite = new ToolItem(toolBar, SWT.NONE);
tltmWhite.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(white);
}
});
tltmWhite.setText("White");
ToolItem tltmRed = new ToolItem(toolBar, SWT.NONE);
tltmRed.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(red);
}
});
tltmRed.setText("Red");
ToolItem tltmWidgetBackground = new ToolItem(toolBar, SWT.NONE);
tltmWidgetBackground.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(widgetBackground);
}
});
tltmWidgetBackground.setText("Widget Background");
ToolItem tltmNewRgb = new ToolItem(toolBar, SWT.NONE);
tltmNewRgb.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
table.setBackground(rowColor);
}
});
tltmNewRgb.setText("New RGB");
table = new Table(this, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.addListener(SWT.EraseItem, new Listener() {
@Override
public void handleEvent(Event event) {
System.out.println("Erase Item event has fired.");
event.gc.setBackground(((TableItem) event.item).getBackground());
event.gc.fillRectangle(event.getBounds());
}
});
TableColumn tblclmnColumn1 = new TableColumn(table, SWT.NONE);
tblclmnColumn1.setWidth(100);
tblclmnColumn1.setText("Column 1");
TableColumn tblclmnColumn2 = new TableColumn(table, SWT.NONE);
tblclmnColumn2.setWidth(100);
tblclmnColumn2.setText("Column 2");
TableColumn tblclmnColumn3 = new TableColumn(table, SWT.NONE);
tblclmnColumn3.setWidth(100);
tblclmnColumn3.setText("Column3");
table.setSortColumn(tblclmnColumn2);
table.setSortDirection(SWT.UP);
TableItem tableItem = new TableItem(table, SWT.NONE);
tableItem.setText("New TableItem");
TableItem tableItem_1 = new TableItem(table, SWT.NONE);
tableItem_1.setText("New TableItem");
TableItem tableItem_2 = new TableItem(table, SWT.NONE);
tableItem_2.setText("New TableItem");
white = display.getSystemColor(SWT.COLOR_WHITE);
red = display.getSystemColor(SWT.COLOR_RED);
widgetBackground = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
rgb = Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND)
.getRGB();
System.out.println("red: " + rgb.red);
System.out.println("green: " + rgb.green);
System.out.println("blue: " + rgb.blue);
rowColor = new Color(Display.getDefault(), 254, 254, 254);
tableItem.setBackground(rowColor);
tableItem_1.setBackground(rowColor);
tableItem_2.setBackground(rowColor);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
|
|
|
Goto Forum:
Current Time: Fri Apr 26 13:54:39 GMT 2024
Powered by FUDForum. Page generated in 0.03539 seconds
|