1

I am developing GUI in an application (which is based on Spring framework) using Swing. In one of the screens, we have several JButtons, JLabels, JFormattedtextFields and JRadioButtons in a panel. The question is:

1). When I press the tab button from the keyboard, the control does not goe to the JRadioButton field (though it goes to other components before and after it). It does not appear on these radio buttons (a serious issue with the application). How to fix this.

2).Also to set the text(label) for each radio buton, i have to do in separate labels:

<label text="Raiding" constraints="21,1" font="Arial-PLAIN-12" />
    <buttongroup>
    <radiobutton id="raidingYesID"  font="Arial-PLAIN-12"
                    opaque="false" constraints="22,1" label="Yes"/>
    <label text="Yes" constraints="23,1" font="Arial-PLAIN-12" />                   
    <radiobutton id="raidingNOID" font="Arial-PLAIN-12"
                   selected="true" opaque="true" constraints="24,1"/>            
    <label text="No" constraints="25,1" font="Arial-PLAIN-12" />   
    </buttongroup>

I tried to do it in java, but the labels did not appear:

raidingYesID.setLabel("Yes");
raidingYesID.setName("Yes");
raidingNOID.setText("No");

none of them made any difference, but i could get the label on console by using:

System.out.println(raidingYesID.getLabel());

do suggest any solutions...

mKorbel
  • 109,525
  • 20
  • 134
  • 319
sonal
  • 101
  • 1
  • 4
  • 13
  • take first question on priority... – sonal Sep 20 '12 at 08:44
  • looks like a tag is missing - the ui is created by loading a xml? – kleopatra Sep 20 '12 at 08:54
  • also, I would suggest you read the api doc instead of randomly calling methods and hope for the best. Plus never-ever use deprecated methods. – kleopatra Sep 20 '12 at 08:56
  • a) why do you mix labels into a buttongroup? b) the radiobutton with id "raidingNOID" has no text attribute c) why the different opaqueness properties to the two radiobuttons? – kleopatra Sep 20 '12 at 09:02
  • hey kleopatra, thanks for your concern and yes we are using xml along with POJOs for UI. – sonal Sep 20 '12 at 10:32
  • label was required to set the text for the radio button, as no oher way worked out in this context – sonal Sep 21 '12 at 04:56
  • there's something completely wrong ... the text _must_ appear on the button itself (the label only stands in the way, f.i. the radiobutton doesn't appear focused). As long as you can't make that work, you're stuck -I'm aware that this comment isn't overly helpful, as you noticed that yourself, but make it nevertheless: you _must_ figure out how to make the text appear: throw out everything else - just one radiobutton with a text attribute, no backend nor binding nor label nor buttongroup. – kleopatra Sep 21 '12 at 06:55

1 Answers1

1

For your second question: use setText() to set the JRadioButton text and use getText() to get it back. The button text can also be set in the constructor.

Dan D.
  • 32,246
  • 5
  • 63
  • 79
  • it worked after increasing the gui's xml attribute: actually it was not able to appear since it had less pixels(or dlus) previously assined. – sonal Sep 21 '12 at 07:23
  • also by setting the attribute text="Yes" in radiobutton: – sonal Sep 21 '12 at 07:27