|
-
Apr 15th, 2003, 11:15 AM
#1
Thread Starter
Addicted Member
resetting components ...
how would I go about resetting combo boxes/radio buttons or checkboxes at a button click?
Code:
if (e.getSource() == JButClear)
{
name.setText(" ");
age.setText(" ");
}
-
Apr 15th, 2003, 01:34 PM
#2
Hyperactive Member
Code:
if (e.getSource() == JButClear)
{
name.setText("");
age.setText("");
myCheckBox.setSelected(false); //Deselects the checkbox
myRadioButton.setSelected(false); //Deselects the radio button
myComboBox.setSelectedIndex(0); //Sets to the first object
myComboBox.removeAll(); //Removes all items
}
Don't use a space to reset the textfields. rather send a blank string like above. Sending a space puts a space in the textbox and it can get rather irritating. Not sure if you wanted to set the combo box to the first item or to clear it, so I added code for both.
Hope that helps
Marnitz
-
Apr 16th, 2003, 12:51 AM
#3
Thread Starter
Addicted Member
Tried as you suggested, but it would not compile
error:
---------- Javac ----------
System2.java:525: cannot resolve symbol
symbol : method setSelected (boolean)
location: class java.awt.Checkbox
cbMale.setSelected(false); //Deselects the radio buttons
^
System2.java:526: cannot resolve symbol
symbol : method setSelected (boolean)
location: class java.awt.Checkbox
cbFemale.setSelected(false);
^
2 errors
Normal Termination
Output completed (0 sec consumed).
any suggestions?
-
Apr 16th, 2003, 12:15 PM
#4
Hyperactive Member
What jdk are you using?
Can you post your declarations for cbMale and cbFemale
-
Apr 16th, 2003, 01:18 PM
#5
Thread Starter
Addicted Member
jdk 1.3.1
Code:
public class System2 extends JFrame implements ActionListener, ItemListener{
....
String vgender;
CheckboxGroup oneCBG;
Checkbox cbMale, cbFemale;
.....
public System2() {
...
myOpts = new JPanel();
EtchedBorder opts = new EtchedBorder();
myOpts.setBorder(new TitledBorder(opts, " Gender: "));
c.ipadx = 12;
c.ipady = 12;
c.gridx=3;
c.gridy=6;
c.gridheight = 2;
gridbag.setConstraints(myOpts, c);
contentPane.add(myOpts);
oneCBG = new CheckboxGroup();
cbMale = new Checkbox("Male", false, oneCBG);
myOpts.add(cbMale);
cbMale.addItemListener(this);
cbFemale = new Checkbox("Female", false, oneCBG );
myOpts.add(cbFemale);
cbFemale.addItemListener(this);//additemListeners
...
public void actionPerformed(ActionEvent e){
if (e.getSource() == JButSubmit)
{
TADisplay.setText ((vgender);
}
public void itemStateChanged(ItemEvent e) {
if (e.getItemSelectable() == cbMale) {
vgender =("Male");
}
if (e.getItemSelectable() == cbFemale) {
vgender = ("Female");
}
...
}
}
-
Apr 16th, 2003, 01:56 PM
#6
Hyperactive Member
Sorry thought you were using JCheckbox
I think its setState(false) then
-
Apr 16th, 2003, 03:05 PM
#7
Thread Starter
Addicted Member
-
Apr 17th, 2003, 05:47 AM
#8
setState
public void setState(boolean state)
Sets the state of this check box to the specified state. The boolean value true indicates the "on" state, and false indicates the "off" state.
Note that this method should be primarily used to initialize the state of the checkbox. Programmatically setting the state of the checkbox will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.
Parameters:
state - the boolean state of the check box
See Also:
getState()
From the documentation of java.awt.Checkbox
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 18th, 2003, 12:43 PM
#9
Hyperactive Member
Ah so my memory hasn't failed me yet 
I don't see your actionlistener for jbutclear. Can you post it the way you have implemented it. You might also need to refresh refresh the control by calling myCheckBox.repaint(); straight after you change the state
-
Apr 19th, 2003, 02:21 AM
#10
Thread Starter
Addicted Member
this is what I have that relates to JbutClear:
Code:
...
JButton JButSubmit, JButClear, JButDisplay;
...
Icon clear = new ImageIcon("clear.gif");
JButClear = new JButton(clear);
c.ipadx = 12;
c.ipady = 13;
c.gridx = 0;
c.gridy = 14;
c.gridwidth = 1;
c.weighty = 3.0;
gridbag.setConstraints(JButClear, c);
contentPane.add(JButClear);
JButClear.addActionListener(this);
....
public void actionPerformed(ActionEvent e){
if (e.getSource() == JButClear)
{
jtffName.setText("");
jtfstreet.setText("");
jtfsName.setText("");
jtfstreet.setText("");
jtfcity.setText("");
jtfcounty.setText("");
jtfpcode.setText("");
jtfphone.setText("");
jtfurl.setText("");
TADisplay.setText("");
TADisplay2.setText("");
checkFB.setSelected(false); //Deselects checkboxes
checkAer.setSelected(false);
checkTen.setSelected(false);
checkGym.setSelected(false);
checkKar.setSelected(false);
checkHoc.setSelected(false);
cboMonth.setSelectedIndex(0); //Sets to the first object
cboDate.setSelectedIndex(0);
cboYear.setSelectedIndex(0);
}
-
Apr 19th, 2003, 07:15 AM
#11
Hyperactive Member
Everything looks in order. What you can try is to call checkHoc.repaint(); after you clear it. I don't have java installed anymore so I can't test it for you. It gave way to .net :/
-
Apr 19th, 2003, 07:20 AM
#12
Thread Starter
Addicted Member
Thanks for your help with this, I appreciate it.
Cheers, Sarah
-
Apr 19th, 2003, 08:46 AM
#13
Thread Starter
Addicted Member
Originally posted by CornedBee
mbonfyre: I think you need a JButtWipe variable somewhere. [/B]
Whats the prob with appreciation?
-
Apr 20th, 2003, 10:57 PM
#14
Thread Starter
Addicted Member
-
Apr 21st, 2003, 10:49 AM
#15
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|