Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

I have in my GUI and two radio button choco and gecode and under each button (choco or gecode)I have 2 radio buttons solution optimal and Feasible solution: my problem lies in the selection buttons. Let me explain:

when I click the radio button choco, I want to have the optimal solution of the model choco so I click on the optimal solution, but the radio button choco is no longer selected but i need it to be selected , the same for the gecode button.
here is a piece of code but it does not work incorrectly:
Java
if ( radio1.isSelected())// button for choco model
 {
    {

/////code
  if ( radio3.isSelected())// button for choco optimal solution
 {
       res=model.find_Optimal_Solution(n, m, R1, C1, B1, Dr1, Dc1, Db1, GainMatrix1);
       for(int i=0;i<n;i++)
       {
        for(int j=0;j<m;j++)
    System.out.print(res[i][j]+" " );
        System.out.println();
 }
 }
       else if ( radio4.isSelected())// button for choco fesable solution  
 {
       res2=model.find_realizable_solution(n, m, R1, C1, B1, Dr1, Dc1, Db1);
       System.out.println("///////////////////////////" );
       for(int i=0;i<n;i++)
       {
        for(int j=0;j<m;j++)
    System.out.print(res2[i][j]+" " );
        System.out.println();
 }}
 }
else if ( radio2.isSelected())  // button for Gocode model
 {
    if( radio5.isSelected())// button for gecode optimal solution   
    {
////some code
    }
 else if( radio6.isSelected())// button for gecode fesable solution  
   {
   }
}


what I want is that when I select the radio button choco remains selected when I select fesable or Optimal solution that belong to this choco button (same thing for the radio button gecode)

Can YOU help me to solve this problem??

is it preferable to choose another way other than the radio buttons to these satsfaire these conditions?

Thank you very much for your help
Posted

1 solution

If you check the JavaDoc for a JRadioButton, you would see it suggests putting radio buttons into a ButtonGroup[^]. Buttons in ButtonGroups allow only one JRadioButton per group to be selected.

Alternatively, you can put the buttons in separate containers to achieve the same effect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900