Ich möchte einen RadioButton an einen String binden. Wenn der String "x" ist, soll der RadioButton ausgewählt werden, wenn der String "y" ist, soll der RadioButton nicht ausgewählt werden. Zumindest habe ich herausgefunden, dass ich einen beansbinding.Converter brauche. Das habe ich versucht, aber es hat nicht funktioniert.
public class TypToBooleanConverter extends Converter {
@Override
public Object convertForward(Object value) {
return value.toString().equals("x");
}
@Override
public Object convertReverse(Object value) {
if (value.toString().equals("true")) {
return "x";
}
else {
return false;
}
}}
Aber dann erhalte ich Ausnahmen. Hoffe, dass jemand mir dabei helfen kann.
Aktualisierung:
Hier ist der vollständige Stack-Trace:
Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException
at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859)
at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665)
at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
... 27 more
Caused by: org.jdesktop.beansbinding.PropertyResolutionException: Exception invoking method public void org.jdesktop.swingbinding.adapters.AbstractButtonAdapterProvider$Adapter.setSelected(boolean) on org.jdesktop.swingbinding.adapters.AbstractButtonAdapterProvider$Adapter@1958bf9
at org.jdesktop.beansbinding.BeanProperty.invokeMethod(BeanProperty.java:791)
at org.jdesktop.beansbinding.BeanProperty.write(BeanProperty.java:891)
at org.jdesktop.beansbinding.BeanProperty.setValue(BeanProperty.java:571)
at org.jdesktop.beansbinding.Binding.refreshUnmanaged(Binding.java:1229)
at org.jdesktop.beansbinding.Binding.refresh(Binding.java:1207)
at org.jdesktop.beansbinding.AutoBinding.tryRefreshThenSave(AutoBinding.java:162)
at org.jdesktop.beansbinding.AutoBinding.sourceChangedImpl(AutoBinding.java:227)
at org.jdesktop.beansbinding.Binding.sourceChanged(Binding.java:1411)
at org.jdesktop.beansbinding.Binding.access$1200(Binding.java:38)
at org.jdesktop.beansbinding.Binding$PSL.propertyStateChanged(Binding.java:1618)
at org.jdesktop.beansbinding.PropertyHelper.firePropertyStateChange(PropertyHelper.java:212)
at org.jdesktop.beansbinding.ELProperty.notifyListeners(ELProperty.java:688)
at org.jdesktop.beansbinding.ELProperty.access$800(ELProperty.java:155)
at org.jdesktop.beansbinding.ELProperty$SourceEntry.processSourceChanged(ELProperty.java:312)
at org.jdesktop.beansbinding.ELProperty$SourceEntry.sourceChanged(ELProperty.java:326)
at org.jdesktop.beansbinding.ELProperty$SourceEntry.propertyChange(ELProperty.java:333)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
at lagerverwaltung.articleEditor.setCurrentRecord(articleEditor.java:42)
at lagerverwaltung.LagerverwaltungView.newRecord(LagerverwaltungView.java:141)
... 32 more
Caused by: java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jdesktop.beansbinding.BeanProperty.invokeMethod(BeanProperty.java:782)
... 51 more