Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two really important questions

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I have several jtextfields in a Jwindow ,
my major problem I cannot get the cursor to appear in the first jtextfield , the user would need to click on it this doesnt look too professional. I can I solve this?
2) Under the above jtextfields there are 3
jradiobuttons which are included in a buttongroup. The user has the option of picking one of the 3, but this is optional. My problem if someone happens to pick one and then decides he no longer wishes to he is unable to remove his choice. How can i bring the radiobuttons to their original state? I have tried
ButtonGroup.setSellected(ButtonModel
button1, false);
repaint();
but with no success can someone please help
thank u all and a great new year
------------------
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ans 1) You can explicitly set focus to the textfield using
textfield.requestFocus(); when your app loads.
Note: this works only in application & not in applet, which is a bug in JDK.
Ans2) I don't understand how the user is not able to select another choice, could u pls post ur code, because in normal cases in a buttongroup u can select only "1 at a time", so after selecting one, if you want to select another u can do so but the previous selection goes.
 
Rajasekaran Anand
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can use requestFocus method of JTextField
for cursor display during startup of the
JWindow.You can do this part in
WindowListener's windowOpened method.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your second you could always add a radio button option for none. I have noticed it as well and copped out with adding a none option. So I haven't actually spent alot of time trying. I tried what you did and it didn't work. But since the option had to be something the user did I just added another radio button.
 
Renee Zhang
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the question#2. I paste sth. from sun tutorial

You should generally initialize a group of radio buttons so that one is selected. However, the API doesn't enforce this rule -- a group of radio buttons can have no initial selection. Once the user has made a selection, exactly one button is selected from then on. There's no supported API for unselecting all the buttons. However, if you really want to unselect all the buttons (not that we recommend it), invoking setSelected(null, true) on the ButtonGroup should do the trick.

I tryed myButtongroup.setSelected(null, true); It works but not very well...
Good luck!
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Why not associate a listener with each radio button and if a button is clicked when it is already selected call that null method on the group.
That way the user can alter the selection or undo the selection they just made. I suggest you include a tooltip to explain that functionality as it's not what all users may think of.
Hope that helps,
Terry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic