I'd like to create a toggle action with Karsten Letzsch UI-Framework
1.4. As opposed to my expectations, the two related toggle buttons do
not disable each other, but as soon as clicking the second one, both
just stick in their pushed state. What am I doing wrong?
--- Code ---
import com.jgoodies.binding.beans.*;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.uif.action.*;
import com.jgoodies.uif.builder.ToolBarBuilder;
import java.awt.BorderLayout;
import java.util.ResourceBundle;
import javax.swing.JFrame;
public class Test extends JFrame {
private static final String ID1 = "1";
private static final String ID2 = "2";
public static void main(String[] args) {
new Test();
}
public Test() {
final Settings settings = new Settings();
final ValueModel valueModel =
new PropertyAdapter(settings, Settings.SIMPLE_PROPERTY);
ActionManager.setBundle(ResourceBundle.getBundle("Action"));
ActionManager.register(ID1,
ToggleAction.createRadio(valueModel,
Boolean.TRUE));
ActionManager.register(ID2,
ToggleAction.createRadio(valueModel,
Boolean.FALSE));
final ToolBarBuilder builder = new ToolBarBuilder();
builder.addToggle((ToggleAction) ActionManager.get(ID1));
builder.addToggle((ToggleAction) ActionManager.get(ID2));
getContentPane().add(builder.getToolBar(), BorderLayout.NORTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200, 100);
setVisible(true);
}
public static class Settings extends Model {
public static final String SIMPLE_PROPERTY = "simpleProperty";
private Boolean simpleProperty = Boolean.TRUE;
public void setSimpleProperty(Boolean simpleProperty) {
final Boolean old = getSimpleProperty();
this.simpleProperty = simpleProperty;
firePropertyChange(SIMPLE_PROPERTY, old, simpleProperty);
}
public Boolean getSimpleProperty() {
return simpleProperty;
}
}
}
--- Properties ---
1.LABEL = 1
2.LABEL = 2
Thanks for your advice.
Daniel Frey
Daniel Frey - 06 Jun 2005 16:16 GMT
I found an answer: I think the default value for the method has
changed.
final ValueModel valueModel =
new PropertyAdapter(settings, Settings.SIMPLE_PROPERTY,
true);
does do the job.
Daniel Frey