This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding controls at runtime  RSS feed

 
jayram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello frens
Is it possible to add swing controls at runtime??ie thing like conditional addition. I have a typical problem...
I dont know before hand if i need to show a textbox or a combobox or some other control. I need to display appropriate control at runtime depending on the user who has logged in and his user preferences...so how can i do that?
and please dont tell me its impossible :O ..i badly need a solution

TYI

------------------
What if this is as good as it gets ?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.4 has a CLASS for implementing User Preferences. Although I haven't had a chance to look at it yet. What I have done though is create a DAT file (text file) that contains user preferences that are read when the program loads. I assume you are talking about who is logged into your program and not the OS itself. As long as this is the case, that should solve your problem.
Simply read in the appropriate DAT file determined by the program when the User logs in
Psuedo Code
if (User == "Johnny") {
load Johnny.DAT
}
etc......
Hope that at least gets you started.

------------------
Happy Coding,
Gregg Bolinger
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg I hope you are using java.util.Properties.
joshi,
Yes you can add or not add components. If your designs are radically different, you might consider separate panels and add the appropriate one based on user pref. If they are minor, you either add the component or not.
if (userAuthorized)
add(component)
 
jayram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
paul/greg
My problem is i do not know the component class till the runtime.I have a panel on which standard components are there which are available to all users. But any user can choose to have some more fields and the 'class' of this is unknown till runtime. The user can choose to have a textbox/a combobox/listbox/radionbutton/checkbox.So depending on user preference i need to instantiate proper class.I want to add if else blocks like
if(userPref=textbox)
instantiate a textfield
if(userpref=combo)
instantiate a combo..
and so on.Instead i need a more object oriented solution.I think reflection might be of some use but havent figured out exactly how to do it


------------------
What if this is as good as it gets ?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!