Method that returns an enabled JComboBox [on hold]
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:
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 JComboBox
in 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
New contributor
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.
|
show 4 more comments
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:
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 JComboBox
in 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
New contributor
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 callsgetEnabledJComboBox()
, 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
|
show 4 more comments
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:
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 JComboBox
in 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
New contributor
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:
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 JComboBox
in 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
java swing
New contributor
New contributor
edited Dec 20 at 16:09
New contributor
asked Dec 20 at 15:43
El Bryan
11
11
New contributor
New contributor
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 callsgetEnabledJComboBox()
, 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
|
show 4 more comments
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 callsgetEnabledJComboBox()
, 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
|
show 4 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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