Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

JGoodies UIF Toggle Button Example

Thread view: 
Daniel Frey - 05 Jun 2005 20:33 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.