Hi Lan,
Changing the background image on the fly should not be a problem. Does the
snippet below work for you (change the image filenames to be loaded)? If
not then which platform and eclipse version are you using? And if the
snippet does work for you then it must be something more specific to your
context, so you'll have to provide a snippet that shows the problem
happening.
static int counter = 0;
public static void main(String[] args) {
final Display display = new Display();
final Image image1 = new Image(display, "c:\\picture.jpg"); // <--
final Image image2 = new Image(display, "c:\\marbles.gif"); // <--
final Shell shell = new Shell(display);
shell.setBounds(10,10,300,300);
shell.setLayout(new GridLayout());
final Table table = new Table(shell, SWT.NONE);
new TableItem(table, SWT.NONE).setText("item");
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
final Text text = new Text(shell, SWT.SINGLE);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
shell.open();
Runnable runnable = new Runnable() {
public void run() {
table.setBackgroundImage(counter++ % 2 == 0 ? image1 : image2);
display.timerExec(5000, this);
}
};
display.timerExec(1000, runnable);
shell.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
text.setFocus();
}
});
table.setFocus();
while (!shell.isDisposed()){
if (!display.readAndDispatch()) display.sleep();
}
image1.dispose();
image2.dispose();
display.dispose();
}
Grant
"Lan" <lanlan99999@xxxxxxxxxxx> wrote in message
news:ftbmui$kbh$1@xxxxxxxxxxxxxxxxxxxx
Hi guys,
I have a RCP application that I want to change some control's background
image on the fly. I tried control.setBackgroundImage(image); The new
image appeared on the control. However, when I resize the rcp
application, the view that contains the control(a table) loss focus and
the previous image appears again... I then tried:
control.getBackgroundImage().dispose();
control.setBackgroundImage(image);
However non of the two images are showing up any more... Can somebody
show me the correct way to switch background colour and background image
on the fly(It is already showing)?
Thank you in advance,
Lan