rossryan
asked on
JRadioButton isn't visible
Hello,
The initial RadioButton is visible, but the other buttons either aren't being added correctly, or they aren't visible.
Can someone please take a look?
Thanks,
Ryan
The initial RadioButton is visible, but the other buttons either aren't being added correctly, or they aren't visible.
Can someone please take a look?
Thanks,
Ryan
if(((iQuestion)(questions.get(Index))).GetPreferredQuestionHandlingType().equals("RadioButton")){
ArrayList choices = ((iQuestion)(questions.get(Index))).GetChoices();
jRadioButton_Answer.setText(choices.get(0).toString());
jRadioButton_Answer.setVisible(true);
answersgroup.add(jRadioButton_Answer);
for(int i = 1; i < choices.size(); i++)
{
JRadioButton newButton = new JRadioButton();
this.add(newButton);
newButton.setText(choices.get(i).toString());
newButton.setVisible(true);
newButton.setLocation(jRadioButton_Answer.getLocation().x, jRadioButton_Answer.getLocation().y - 10);
answersgroup.add(newButton);
}
}
public class TrueFalseQuestion implements iQuestion {
public TrueFalseQuestion() {
}
private String questionText = "";
private boolean correctAnswer = false;
private String questionType = "True or False Question";
private boolean studentsAnswer = false;
private boolean haschoices = true;
private boolean hassecondarychoices = false;
private String preferredquestionhandlingtype = "RadioButton";
private DefaultTableModel receivedanswers = new DefaultTableModel();
public boolean GetCorrectAnswer(){
return correctAnswer;
}
public void SetCorrectAnswer(boolean Answer){
correctAnswer = Answer;
}
public String GetQuestionType()
{
return questionType;
}
public String GetQuestionText()
{
return questionText;
}
public void SetQuestionText(String text)
{
questionText = text;
}
public boolean HasChoices(){
return haschoices;
}
public boolean HasSecondaryChoices(){
return hassecondarychoices;
}
public ArrayList GetSecondaryChoices() {
return new ArrayList();
}
public String GetPreferredQuestionHandlingType() {
return preferredquestionhandlingtype;
}
public ArrayList GetChoices() {
ArrayList choices = new ArrayList();
choices.add("True");
choices.add("False");
return choices;
}
public void SetReceivedAnswers(DefaultTableModel Answers)
{
receivedanswers = Answers;
}
public DefaultTableModel GetReceivedAnswers() {
return receivedanswers;
}
}
ASKER
Even with the modified code, it doesn't display.
for(int i = 1; i < choices.size(); i++)
{
JRadioButton newButton = new JRadioButton("Test");
newButton.setText(choices. get(i).toS tring());
newButton.setVisible(true) ;
newButton.setLocation(jRad ioButton_A nswer.getL ocation(). x, jRadioButton_Answer.getLoc ation().y - (i * 10));
this.add(newButton);
answersgroup.add(newButton );
}
for(int i = 1; i < choices.size(); i++)
{
JRadioButton newButton = new JRadioButton("Test");
newButton.setText(choices.
newButton.setVisible(true)
newButton.setLocation(jRad
this.add(newButton);
answersgroup.add(newButton
}
Is this enough space to show it?
are you sure your choices array is actually filled?
what type is answersgroup?
are you sure your choices array is actually filled?
what type is answersgroup?
ASKER
Here's a screenshot of the program in action. The "True" RadioButton that is visible was created via the designer, and the "False" RadioButton isn't visible (created programmatically).
Any ideas?
Thanks,
Ryan
Screenshot-3.png
Any ideas?
Thanks,
Ryan
Screenshot-3.png
Again:
are you sure your choices array is actually filled?
Are you sure you have enough space in the container?
what type is answersgroup?
are you sure your choices array is actually filled?
Are you sure you have enough space in the container?
what type is answersgroup?
make sure answersgroup has a null layout manager
ASKER
Will do.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please accept your own (last) comment as the answer. That way this question will be closed without any points (since you found a solution yourself)
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
won't this put all of them at the exactly same place (so just one will be visible)?