Skip to content

Java Swing property sheet component to quickly create settings menus

License

Notifications You must be signed in to change notification settings

Dacaspex/PropertySheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PropertySheet

Java Swing property sheet component. Build settings menus on the fly.

Example image of property sheet

How it works, simply

The PropertySheet is an augmented JTable to which you can quickly add properties. These are then rendered in a sort of settings menu style.

IntegerProperty prop1 = new IntegerProperty("My integer property", 42);
FloatProperty prop2 = new FLoatProperty("My float property", 11.12);

PropertySheet sheet = new PropertySheet(new PropertySheetOptions());
sheet.addProperty(prop1);
sheet.addProperty(prop2);

Supperted values out of the box

The following types are supported out of the box with this library:

  • Integer
  • Long
  • Double
  • Float
  • Color
  • Boolean
  • String
  • Selection (drop down menu)

Validation

Properties can have numerous (custom) validators to make sure the value is what you want it to be.

IntegerProperty prop = new IntegerProperty(
   "My integer property",
   42,
   new CompoundValidator(
       new IntegerValidator(),
       new IntegerRangeValidator(30, 50)
   )
);

Or even easier with a Factory!

IntegerProperty prop = new IntegerProperty(
   "My integer property",
   5,
   new IntegerValidatorFactory()
       .setRange(-5, 10)
       .allowZero(false)
       .build()
);

Custom properties

You can create custom properties with custom renderers and editors (as long as the JTable supports it). These can be added via various methods in the PropertySheet class.

Event listeners

Add event listeners to listen for update or create events.

class EventListener implements PropertySheetEventListener {
     @Override
     public void onPropertyUpdated(Property property) {
         // TODO
     }
      @Override
     public void onPropertyAdded(Property property) {
         // TODO
     }
 }
 
 sheet.addEventListener(new EventListener());

Or let your event listener class extend the PropertySheetEventAdapter for easier use.