Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Creating GUI lists dynamically

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on creating a GUI application (in particular, a sensor responsive system). So you can imagine the system having a list of possible responses to execute when a set of conditions are met. To start, I have created a bunch of default responses (each a separate Java class subclassed from an abstract base class) but I would like to maintain the ability for future developers to create their own custom responses and have them included in the system without having to modify the original source.

So if I want to present to the operator (or user of the system) a list of available responses (in the GUI as a JComboBox), what's the best way for that list to be generated without hard coding the list in the original source? I thought of using a combination of directory scanning (looking for class files that meet a certain name) and reflection to create the necessary response classes.

Is this the best approach, or have I missed something?

Thanks,
Dave
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I might be missing the complexity of your question, but it seems to me you would want a separate "Model" class that extends DefaultComboBoxModel. This would read in the values for the JComboBoxes dynamically, either from a database, an XML file, or whatever. Then, the other developers could just modify the data source and not the code.
[ August 22, 2005: Message edited by: Tim McGuire ]
 
What are you doing? You are supposed to be reading this tiny ad!
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic