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

rossryanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VenabiliCommented:
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)?
rossryanAuthor Commented:
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);            
             }
VenabiliCommented:
Is this enough space to show it?
are you sure your choices array is actually filled?

what type is answersgroup?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

rossryanAuthor Commented:
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
VenabiliCommented:
Again:
are you sure your choices array is actually filled?
Are you sure  you have enough space in the container?
what type is answersgroup?
Mick BarryJava DeveloperCommented:
make sure answersgroup has a null layout manager
rossryanAuthor Commented:
Will do.
rossryanAuthor Commented:
Hmm. The solution was to add everything to a JPanel, then add that JPanel to the higher up JPanel.



-Ryan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSr. Software engineerCommented:
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)
Kevin CrossChief Technology OfficerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.