2

SwingアプリケーションでJProgressbarをBeanクラスのプロパティにバインドする方法のサンプルコードまたはリンクを提供できる人はいますか?

4

1 に答える 1

2

JGoodies Binding を使用して、進行状況バーをモデルにバインドできます。ただし、これが機能するには、(ビュー) モデルがプロパティ変更イベントを発生させる必要があります。 http://www.jgoodies.com/downloads/libraries.html月曜日にサンプル コードを投稿できます。

例:

あなたのViewModelで:

private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

private int progress;

public void addPropertyChangeListener(PropertyChangeListener listener)
{
    changeSupport.addPropertyChangeListener(listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener)
{
    changeSupport.removePropertyChangeListener(listener);
}

public int getProgress()
{
    return progress;
}

public static final String PROPERTY_PROGRESS = "progress";

public void setProgress(int progress)
{
    int old = this.progress;
    this.progress = progress;
    changeSupport.firePropertyChange(PROPERTY_PROGRESS, old, progress);
}

あなたのビューで:

BeanAdapter<ViewModel> beanAdapter = new BeanAdapter<ViewModel>(viewModel, true);
Bindings.bind(progressBar, "value", beanAdapter.getValueModel(ViewModel.PROPERTY_PROGRESS));
于 2011-10-09T12:28:44.290 に答える