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...

7
  • take first question on priority...
    – sonal
    Sep 20, 2012 at 8:44
  • looks like a tag is missing - the ui is created by loading a xml?
    – kleopatra
    Sep 20, 2012 at 8: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, 2012 at 8: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, 2012 at 9:02
  • hey kleopatra, thanks for your concern and yes we are using xml along with POJOs for UI.
    – sonal
    Sep 20, 2012 at 10:32

1 Answer 1

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.

2
  • it worked after increasing the gui's xml attribute: <layout type="FormLayout" columns=" 50dlu,13dlu,2dlu,15dlu,7dlu, 13dlu,2dlu,15dlu,7dlu,15dlu, 2dlu,15dlu,55dlu,70dlu,15dlu, 15dlu,15dlu,15dlu,15dlu,50dlu,25dlu,30dlu, 35dlu,10dlu"> actually it was not able to appear since it had less pixels(or dlus) previously assined.
    – sonal
    Sep 21, 2012 at 7:23
  • also by setting the attribute text="Yes" in radiobutton: <radiobutton id="raidingYesID" font="Arial-PLAIN-12" opaque="false" constraints="22,1" text="Yes"/>
    – sonal
    Sep 21, 2012 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.