[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] ExpandBar and ExpandItem questions
|
- From: Nik Bhattacharya <nik_bhat@xxxxxxxxx>
- Date: Tue, 05 Dec 2006 18:21:37 -0600
- Newsgroups: eclipse.platform.swt
- Organization: EclipseCorner
- User-agent: Thunderbird 1.5.0.8 (Windows/20061025)
I really like the look of the ExpandBar and ExpandItem. However, I want
to change the colors of the background. Now I looked at an earlier
thread in the attachment that was asking about setting the background.
Seems like the bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=131265
has been fixed. However setting the background on the ExpandBar to a
different color totally obliterates all the painting operations.
See before and after. The only difference is that the second image is
captured when
expandBar.setBackground(myTancolor)
is called.
I tried setting a background image, but that gets ignored unless
setBackground is called as well, and in any case the nice rendering of
the rounded edges and the round up/down button is all lost once
setBackground is called.
What are my options? I don't mind writing custom paint operations, but
I don't see where.
Thanks for any help,
Nik
Snippet below
---------------
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class ExpandBarComposite extends Composite {
private ExpandItem networkToolsExpandItem;
private ExpandItem workflowExpandItem;
private ExpandItem quickSearchExpandItem;
private Composite workflowComposite;
private Composite searchComposite;
private ExpandBar expandBar;
private Text text;
private Composite networkToolsComposite;
private Image oldImage;
private Color tanColor;
/**
* Create the composite
* @param parent
* @param style
*/
public ExpandBarComposite(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout());
createControl(this);
}
protected void createControl(Composite parent)
{
expandBar = new ExpandBar (parent, SWT.NONE);
//tanColor = new Color(parent.getDisplay(), 207, 196, 177);
expandBar.setBackground(tanColor);
Image image = Display.getDefault().getSystemImage(SWT.ICON_INFORMATION);
// First item
searchComposite = new Composite (expandBar, SWT.NONE);
GridLayout layout = new GridLayout ();
layout.numColumns = 2;
layout.marginLeft = layout.marginTop = layout.marginRight =
layout.marginBottom = 10;
layout.verticalSpacing = 10;
searchComposite.setLayout(layout);
text = new Text(searchComposite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Button searchButton = new Button (searchComposite, SWT.PUSH);
searchButton.setText("Search");
quickSearchExpandItem = new ExpandItem (expandBar, SWT.NONE, 0);
quickSearchExpandItem.setExpanded(true);
quickSearchExpandItem.setText("Quick Search");
quickSearchExpandItem.setHeight(searchComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
quickSearchExpandItem.setControl(searchComposite);
// Second item
workflowComposite = new Composite (expandBar, SWT.NONE);
layout = new GridLayout (2, false);
layout.marginLeft = layout.marginTop = layout.marginRight =
layout.marginBottom = 10;
layout.verticalSpacing = 10;
workflowComposite.setLayout(layout);
Label label = new Label (workflowComposite, SWT.NONE);
final Label importDevicesLabel = new Label (workflowComposite, SWT.NONE);
importDevicesLabel.setText("Import Devices");
label = new Label (workflowComposite, SWT.NONE);
final Label backupDevicesLabel = new Label (workflowComposite, SWT.NONE);
backupDevicesLabel.setText("Backup Devices");
label = new Label (workflowComposite, SWT.NONE);
final Label createAWorkingLabel = new Label (workflowComposite, SWT.NONE);
createAWorkingLabel.setText("Create a Working Set");
label = new Label (workflowComposite, SWT.NONE);
final Label createARuleLabel = new Label (workflowComposite, SWT.NONE);
createARuleLabel.setText("Create a Rule");
workflowExpandItem = new ExpandItem (expandBar, SWT.NONE, 1);
workflowExpandItem.setExpanded(true);
workflowExpandItem.setText("Workflow Help");
workflowExpandItem.setHeight(workflowComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
workflowExpandItem.setControl(workflowComposite);
// Third item
networkToolsExpandItem = new ExpandItem (expandBar, SWT.NONE, 2);
networkToolsExpandItem.setExpanded(true);
networkToolsExpandItem.setText("Network Tools");
networkToolsComposite = new Composite(expandBar, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 10;
gridLayout.numColumns = 2;
gridLayout.marginBottom = 10;
networkToolsComposite.setLayout(gridLayout);
final Label label_1 = new Label(networkToolsComposite, SWT.NONE);
final Label importDevicesLabel_1 = new Label(networkToolsComposite,
SWT.NONE);
importDevicesLabel_1.setText("Ping");
final Label label_2 = new Label(networkToolsComposite, SWT.NONE);
final Label backupDevicesLabel_1 = new Label(networkToolsComposite,
SWT.NONE);
backupDevicesLabel_1.setText("SSH");
final Label label_3 = new Label(networkToolsComposite, SWT.NONE);
final Label createAWorkingLabel_1 = new Label(networkToolsComposite,
SWT.NONE);
createAWorkingLabel_1.setText("NS Lookup");
final Label label_4 = new Label(networkToolsComposite, SWT.NONE);
final Label createARuleLabel_1 = new Label(networkToolsComposite,
SWT.NONE);
createARuleLabel_1.setText("Trace Route");
networkToolsExpandItem.setHeight(networkToolsComposite.computeSize(SWT.DEFAULT,
SWT.DEFAULT).y);
networkToolsExpandItem.setControl(networkToolsComposite);
expandBar.setSpacing(8);
}
@Override
public void dispose() {
super.dispose();
if(oldImage != null)
{
oldImage.dispose();
}
if(tanColor != null)
{
tanColor.dispose();
}
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.CLOSE);
shell.setText("Expand bar");
shell.setLayout(new FillLayout());
shell.setSize(350, 700);
ExpandBarComposite composite = new ExpandBarComposite(shell, SWT.FILL);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}


--- Begin Message ---
Hi,
I'm trying out Snippet223 with Eclipse3.2M5a with Windows XP. Instead of
having the default windows color, I want to set the background of ExpandBar
widget to WHITE. Then I've added the following codes to Snippet223:
Color whiteColour = display.getSystemColor(SWT.COLOR_WHITE);
bar.setBackground(whiteColour);
The result is it has NO effect on ExpandBar. Is this a bug, something
forbidden, or something I've done wrong with my code?
Regards,
Tony Lam
Australian Nuclear Science and Technology Organisation
--- End Message ---