Link to home
Start Free TrialLog in
Avatar of rossryan
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
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;
    }



}

Open in new window

Avatar of Venabili
Venabili
Flag of Bulgaria image

newButton.setLocation(jRadioButton_Answer.getLocation().x, jRadioButton_Answer.getLocation().y - 10);

won't this put all of them at the exactly same place (so just one will be visible)?
Avatar of rossryan
rossryan

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).toString());
                newButton.setVisible(true);
                newButton.setLocation(jRadioButton_Answer.getLocation().x, jRadioButton_Answer.getLocation().y - (i * 10));
                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?
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
Again:
are you sure your choices array is actually filled?
Are you sure  you have enough space in the container?
what type is answersgroup?
Avatar of Mick Barry
make sure answersgroup has a null layout manager
Will do.
ASKER CERTIFIED SOLUTION
Avatar of rossryan
rossryan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.