wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes two really important questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "two really important questions" Watch "two really important questions" New topic
Author

two really important questions

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
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

Joined: Dec 06, 2000
Posts: 148
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.


- Vinod<br />-------<br />SCJP2
Rajasekaran Anand
Greenhorn

Joined: Sep 13, 2001
Posts: 23

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

Joined: May 17, 2001
Posts: 2823
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

Joined: Sep 10, 2001
Posts: 72
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

Joined: May 30, 2001
Posts: 328
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: two really important questions