• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selection of Radio button, when combo box is selected

 
Sophiya Behera
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am facing a issue in dynamic selection of radio button. I want to select a radio button at runtime and it depends on the selection of combobox. I have tried the following code
radiobutton.setSelected(true) and radiobutton.getmodel().setselected(true). But nothing is working. Please help me in this.


Regards
Sophiya
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that combo box selection event is triggering properly?
 
Sophiya Behera
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swastik,

Thnks for your reply.

Yes the event is triggered properly. I have debugged through each line. After setting setSelected(true) i checked for isSelected(), itis showing true. But in UI, the button is not selected. Could you please tell me any other example, if one simple button is clicked, how the radio button is selected.... That also will help me.



Regards
Sophiya
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sophiya

You can have a look on this


 
Sophiya Behera
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik,
This example works. But my scenario is bit complex. I have created a panel and created group of radio buttons in that panel in a class. And i am trying to get hold of the radio button through button group. Please refer to below code. Please suggest...

Enumeration<AbstractButton> enumButtons;
String[] arrDfltVal = getDfltValArr();

for(int i=0;i<arr.length;i++){

enumButtons = arr[i].getBtnGroup().getElements();
while (enumButtons.hasMoreElements()){


//*AbstractButton ab= enumButtons.nextElement();
JRadioButton ab= (JRadioButton)enumButtons.nextElement();
//arr[i].getBtnGroup().setSelected(ab, true);


if ((ab.getName()).equalsIgnoreCase(arrDfltVal[i])){
System.out.println("isSelected"+ab.isSelected()+ab.getModel().isSelected());
//arr[i].getBtnGroup().setSelected(ab.getModel(), true);
ab.setSelected(true);
System.out.println("isSelected"+ab.isSelected()+ab.getModel().isSelected());

}

}


}
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sophiya

It should be possible that you too. The code could have been better, but I did it in a hurry.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> After setting setSelected(true) i checked for isSelected(), itis showing true. But in UI, the button is not selected.

quite likely you have duplicate declarations of your radioButtons
1) a class field referenced by the listener
2) a local variable where you add the radioButtons to the gui,
these are the radioButtons seen on the screen, but not 'seen' by the listener

would be much easier for you to get a solution if you posted a 'simple' working example
of the problem - just a frame, comboBox, 2 radioButtons and the listener code.
 
Sophiya Behera
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swastik,
My issue is resolved. I have taken the same approach, but i was going wrong while accessing array of buttons. Everytime the values in the array was getting initialised. Thnks for your code.


Regards
Sophiya
 
Sophiya Behera
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael,
My issue is resolved and the reson what you have specified is quite similar to my issue. Thanks for your reply.


Regards
Sophiya
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic