Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » ComboViewer - selections cannot show icons(-- Webmaster, please remove this duplicate post)
ComboViewer - selections cannot show icons [message #1261058] Sun, 02 March 2014 01:00
David Lee is currently offline David Lee
Messages: 24
Registered: May 2013
Junior Member
I tried showing images in TableViewer and TreeViewer by using getImage() like function in LabelProvider, all works very well!

I'd like to implement a Combo with flags/languages just like the picture in "Shadows" paragraph of http://www.eclipse.org/rap/noteworthy/1.4/ ,I tried ComboViewer, the getText() of LabelProvider works well, but the getImage() does not work at all, it cannot show the flag icons! the code is as below, can someone please let me know how to do that?! Thank you!

// where compComboViewer is a Composite container
final Image flagAmerica = SysIcon.loadImage("icon/America.png");
final Image flagChina = SysIcon.loadImage("icon/Canada.png");

// to test if 16x16 icon flagAmerica works, and the answer is YES
Label label = new Label(compComboViewer, SWT.NONE);
label.setImage(flagAmerica);

final ComboViewer cboLocale = new ComboViewer(compComboViewer, SWT.READ_ONLY);
cboLocale.setContentProvider(ArrayContentProvider.getInstance());
cboLocale.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
Country country = (Country) element;
return country.getCountryName();
}
@Override
public Image getImage(Object element) {
Image imgFlag = null;
Country country = (Country) element;
switch ( country.getCountryName() ) {
case "America":
imgFlag = flagAmerica;
break;
case "Canada":
imgFlag = flagCanada;
break;
}
return imgFlag;
}
});
Country[] countries = new Country[]{ new Country("America"), new Country("Canada") };
cboLocale.setInput(countries);

private class Country {
private String countryName;
public Country(String countryName) {
this.countryName = countryName;
}
public String getCountryName() { return this.countryName; }
public void setCountryName(String countryName) { this.countryName = countryName; }
}
  • Attachment: Shadows.png
    (Size: 17.52KB, Downloaded 8 times)

[Updated on: Sun, 02 March 2014 02:15]

Report message to a moderator

Previous Topic:ComboViewer - selections cannot show icons
Next Topic:ComboViewer - cannot show icons of selections
Goto Forum:
  


Current Time: Thu Aug 28 11:33:26 EDT 2014

Powered by FUDForum. Page generated in 0.12020 seconds