Method that returns an enabled JComboBox [on hold]












-2














I have 2 JComboBox usersIds and clientsIds that are initially disabled:



JComboBox<String> usersIds = new JComboBox<>();
JComboBox<String> clientsIds = new JComboBox<>();

usersIds.setEnabled(false);
clientsIds.setEnabled(false);


In my app I can choose whether to enable or disable one of them selecting the radio buttons so only one of them can be enabled at the time:



enter image description here



This is the method I have created to return the currently enabled JComboBox.



public JComboBox getEnabledJComboBox(){
if(usersIds.isEnabled()){
return usersIds;
}
if(clientsIds.isEnabled()){
return clientsIds;
}
return null;
}


The method has to return the currently enabled JComboBoxin order to get the selected item from it and pass it as a parameter in order to create an object called User.



public User createUser(){
User user = new User();
user.setId(getEnabledJComboBox().getSelectedItem().toString());
user.setName("Sam");
return user;
}


I have read that returning null is not a good practice, so I want to change/improve the method, any suggestions?










share|improve this question









New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Mast, πάντα ῥεῖ, t3chb0t, Vogel612 Dec 22 at 11:36


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, πάντα ῥεῖ, t3chb0t, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Welcome to Code Review! Please provide more contextual code for this question, so that we can advise you on alternative designs.
    – 200_success
    Dec 20 at 15:45










  • What else can I put in?
    – El Bryan
    Dec 20 at 15:49






  • 2




    The rest of the class or screen would be good. Otherwise, what are the answers going to say? "Yeah, that's bad. Don't do that." — not too useful.
    – 200_success
    Dec 20 at 15:50






  • 1




    Who calls getEnabledJComboBox(), and what does it do with it?
    – 200_success
    Dec 20 at 15:55






  • 1




    Related: stackoverflow.com/q/5231517/573420
    – Peter Taylor
    Dec 20 at 17:19
















-2














I have 2 JComboBox usersIds and clientsIds that are initially disabled:



JComboBox<String> usersIds = new JComboBox<>();
JComboBox<String> clientsIds = new JComboBox<>();

usersIds.setEnabled(false);
clientsIds.setEnabled(false);


In my app I can choose whether to enable or disable one of them selecting the radio buttons so only one of them can be enabled at the time:



enter image description here



This is the method I have created to return the currently enabled JComboBox.



public JComboBox getEnabledJComboBox(){
if(usersIds.isEnabled()){
return usersIds;
}
if(clientsIds.isEnabled()){
return clientsIds;
}
return null;
}


The method has to return the currently enabled JComboBoxin order to get the selected item from it and pass it as a parameter in order to create an object called User.



public User createUser(){
User user = new User();
user.setId(getEnabledJComboBox().getSelectedItem().toString());
user.setName("Sam");
return user;
}


I have read that returning null is not a good practice, so I want to change/improve the method, any suggestions?










share|improve this question









New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Mast, πάντα ῥεῖ, t3chb0t, Vogel612 Dec 22 at 11:36


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, πάντα ῥεῖ, t3chb0t, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    Welcome to Code Review! Please provide more contextual code for this question, so that we can advise you on alternative designs.
    – 200_success
    Dec 20 at 15:45










  • What else can I put in?
    – El Bryan
    Dec 20 at 15:49






  • 2




    The rest of the class or screen would be good. Otherwise, what are the answers going to say? "Yeah, that's bad. Don't do that." — not too useful.
    – 200_success
    Dec 20 at 15:50






  • 1




    Who calls getEnabledJComboBox(), and what does it do with it?
    – 200_success
    Dec 20 at 15:55






  • 1




    Related: stackoverflow.com/q/5231517/573420
    – Peter Taylor
    Dec 20 at 17:19














-2












-2








-2







I have 2 JComboBox usersIds and clientsIds that are initially disabled:



JComboBox<String> usersIds = new JComboBox<>();
JComboBox<String> clientsIds = new JComboBox<>();

usersIds.setEnabled(false);
clientsIds.setEnabled(false);


In my app I can choose whether to enable or disable one of them selecting the radio buttons so only one of them can be enabled at the time:



enter image description here



This is the method I have created to return the currently enabled JComboBox.



public JComboBox getEnabledJComboBox(){
if(usersIds.isEnabled()){
return usersIds;
}
if(clientsIds.isEnabled()){
return clientsIds;
}
return null;
}


The method has to return the currently enabled JComboBoxin order to get the selected item from it and pass it as a parameter in order to create an object called User.



public User createUser(){
User user = new User();
user.setId(getEnabledJComboBox().getSelectedItem().toString());
user.setName("Sam");
return user;
}


I have read that returning null is not a good practice, so I want to change/improve the method, any suggestions?










share|improve this question









New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have 2 JComboBox usersIds and clientsIds that are initially disabled:



JComboBox<String> usersIds = new JComboBox<>();
JComboBox<String> clientsIds = new JComboBox<>();

usersIds.setEnabled(false);
clientsIds.setEnabled(false);


In my app I can choose whether to enable or disable one of them selecting the radio buttons so only one of them can be enabled at the time:



enter image description here



This is the method I have created to return the currently enabled JComboBox.



public JComboBox getEnabledJComboBox(){
if(usersIds.isEnabled()){
return usersIds;
}
if(clientsIds.isEnabled()){
return clientsIds;
}
return null;
}


The method has to return the currently enabled JComboBoxin order to get the selected item from it and pass it as a parameter in order to create an object called User.



public User createUser(){
User user = new User();
user.setId(getEnabledJComboBox().getSelectedItem().toString());
user.setName("Sam");
return user;
}


I have read that returning null is not a good practice, so I want to change/improve the method, any suggestions?







java swing






share|improve this question









New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Dec 20 at 16:09





















New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Dec 20 at 15:43









El Bryan

11




11




New contributor




El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






El Bryan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Mast, πάντα ῥεῖ, t3chb0t, Vogel612 Dec 22 at 11:36


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, πάντα ῥεῖ, t3chb0t, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by Mast, πάντα ῥεῖ, t3chb0t, Vogel612 Dec 22 at 11:36


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Mast, πάντα ῥεῖ, t3chb0t, Vogel612

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    Welcome to Code Review! Please provide more contextual code for this question, so that we can advise you on alternative designs.
    – 200_success
    Dec 20 at 15:45










  • What else can I put in?
    – El Bryan
    Dec 20 at 15:49






  • 2




    The rest of the class or screen would be good. Otherwise, what are the answers going to say? "Yeah, that's bad. Don't do that." — not too useful.
    – 200_success
    Dec 20 at 15:50






  • 1




    Who calls getEnabledJComboBox(), and what does it do with it?
    – 200_success
    Dec 20 at 15:55






  • 1




    Related: stackoverflow.com/q/5231517/573420
    – Peter Taylor
    Dec 20 at 17:19














  • 1




    Welcome to Code Review! Please provide more contextual code for this question, so that we can advise you on alternative designs.
    – 200_success
    Dec 20 at 15:45










  • What else can I put in?
    – El Bryan
    Dec 20 at 15:49






  • 2




    The rest of the class or screen would be good. Otherwise, what are the answers going to say? "Yeah, that's bad. Don't do that." — not too useful.
    – 200_success
    Dec 20 at 15:50






  • 1




    Who calls getEnabledJComboBox(), and what does it do with it?
    – 200_success
    Dec 20 at 15:55






  • 1




    Related: stackoverflow.com/q/5231517/573420
    – Peter Taylor
    Dec 20 at 17:19








1




1




Welcome to Code Review! Please provide more contextual code for this question, so that we can advise you on alternative designs.
– 200_success
Dec 20 at 15:45




Welcome to Code Review! Please provide more contextual code for this question, so that we can advise you on alternative designs.
– 200_success
Dec 20 at 15:45












What else can I put in?
– El Bryan
Dec 20 at 15:49




What else can I put in?
– El Bryan
Dec 20 at 15:49




2




2




The rest of the class or screen would be good. Otherwise, what are the answers going to say? "Yeah, that's bad. Don't do that." — not too useful.
– 200_success
Dec 20 at 15:50




The rest of the class or screen would be good. Otherwise, what are the answers going to say? "Yeah, that's bad. Don't do that." — not too useful.
– 200_success
Dec 20 at 15:50




1




1




Who calls getEnabledJComboBox(), and what does it do with it?
– 200_success
Dec 20 at 15:55




Who calls getEnabledJComboBox(), and what does it do with it?
– 200_success
Dec 20 at 15:55




1




1




Related: stackoverflow.com/q/5231517/573420
– Peter Taylor
Dec 20 at 17:19




Related: stackoverflow.com/q/5231517/573420
– Peter Taylor
Dec 20 at 17:19















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Сан-Квентин

Алькесар

Josef Freinademetz