Repaint Button Icon

Hello everybody,

i´ve got a litte problem and i hope that you can help me.

I´ve got a table with a row of buttons in it. These Buttons all have a icon.

button.setIcon(new ThemeResource("…);

now when i change that icon after an event, how can i force the table respectively the button to repaint and show the new icon?

thx for help


when i click into the table, the icon is updated/repaint and the new icon is shown.
can i fire this event manualy or can somebodey tell me wich method is called?!

Try Table.requestRepaintAll or Table.refreshRowCache.

no, tried both but no repaint of the icon :frowning:

i´ve also tried:

  • table.setContainerDataSource(table.getContainerDataSource());
  • button and table.setImmediate(true);
  • remove all container items and build new container with the old items
  • commit();
  • myComponent.getApplication().getMainWindow().executeJavaScript(“javascript:vaadin.forceSync();”);

another idea?

How about

Container con=table.getContainerDataSource();

Setting the same container directly might not do anything, the above might.

no, the same problem :frowning:

do i also have to repaint/refresh the button?

Hmm… smells like a bug somewhere. can you give us a minimal test application that replicates the problem?

of course:


package com.example.tempproject;

import java.util.Timer;
import java.util.TimerTask;

import com.vaadin.Application;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.*;

public class MyProject extends Application {
	private MyItemContainer container;
	private Table table;

	public void init() {
		Window mainWindow = new Window("Tempproject Application");
		//new BeanItemContainer
		container = new MyItemContainer();
		//new Table to show the items from the container
		table = new Table();
		//new containeritem
		MyContainerItem item = new MyContainerItem();
		Button btn = new Button();
		btn.setIcon(new ThemeResource("icons/32/folder-add.png"));
		//timer to change the icons every 5 seconds
	 * implements a timer that calls
	 * every 5 seconds the method changeicon()

	private void implementTimer() {
		System.out.println("timer implemented");
		Timer timer = new Timer();
		TimerTask timerTask = new TimerTask(){
		  public void run() {
		timer.scheduleAtFixedRate(timerTask, 1000 * 5, 5 * 1000);

	 * changes between the two icons
	public void changeIcon(){
			container.firstItemId().getBtn().setIcon(new ThemeResource("icons/32/users.png"));
		} else if(container.firstItemId().getBtn().getIcon().toString().equals("icons/32/users.png")){
			container.firstItemId().getBtn().setIcon(new ThemeResource("icons/32/folder-add.png"));


package com.example.tempproject;

import com.vaadin.ui.Button;

public class MyContainerItem {
	private Button btn;

	public Button getBtn() {
		return btn;

	public void setBtn(Button btn) {
		this.btn = btn;


package com.example.tempproject;


public class MyItemContainer extends BeanItemContainer<MyContainerItem> {
	public MyItemContainer(){
	 * adds a item to the container
	 * @param item
	public void addItemToContainer(MyContainerItem item){


i hope you get it :slight_smile: tried to skimp it as much as possible

Well that made things much clearer. The icon is not updating because the browser has no way of knowing that the change occurred. Your changeIcon() method runs on the server, but the server does not send anything to the browser until the browser asks the server for something; this is a basic HTTP problem, and has been thoroughly discussed
in this sticky thread

ahhh that´s it :slight_smile:

the workaround with the progressbar solved my problem temporarily.

thank you very much