Please help me with centering a component and clearing a JRadioButton
Hi, could someone help me to cener the label and clear the selected JRadioButton?
I have put a comment beside the problematic place. Thanks a lot! ann
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ButtonAction extends JPanel implements ActionListener {
private JRadioButton button1, button2;
private JButton send, clear;
private JTextField text;
private JLabel label;
private ButtonGroup group;
public ButtonAction() {
setPreferredSize(new Dimension(300, 200));
setLayout(new GridLayout(0, 1, 5, 5));
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
setBorder(BorderFactory.createLineBorder(Color.blue));
JPanel p1 = new JPanel();
button1 = new JRadioButton("Button One");
button2 = new JRadioButton("Button Two");
group = new ButtonGroup();
group.add(button1);
group.add(button2);
p1.add(button1);
p1.add(button2);
JPanel p2 = new JPanel();
send = new JButton("Send");
clear = new JButton("Clear");
label = new JLabel(" ");
label.setAlignmentX(Component.CENTER_ALIGNMENT); //this doesn't work
send.addActionListener(this);
clear.addActionListener(this);
p2.add(send);p2.add(clear);
add(p1); add(p2); add(label);
public void DisplayGUI(){
JFrame frame = new JFrame();
frame.getContentPane().add(this);
frame.pack();
frame.setVisible(true);
public String getButton(){
String result = "";
if (button1.isSelected())
result += "\t You have clicked the first button";
else if (button2.isSelected())
result += "\t You have clicked the second button";
return result;
public void setButton(){ // this method doesn't work
if (button1.isSelected() == true)
button1.setSelected(false);
else if (button2.isSelected() == true)
button2.setSelected(false);
public void actionPerformed (ActionEvent e) {
if (e.getSource() == send) {
label.setText(getButton());
else if (e.getSource() == clear) {
setButton();
label.setText("no button is selected");
public static void main(String[] args) {
ButtonAction ba = new ButtonAction();
ba.DisplayGUI();
}
setHorizontalAlignmentX(Component.CENTER_ALIGNMENT) is a container method and I don't think it does what you think. Try this instead:label = new JLabel("Some text");
//label.setHorizontalAlignmentX(Component.CENTER_ALIGNMENT); //this doesn't work
label.setHorizontalAlignment(SwingConstants.CENTER);When you alter the state of a radio button you should probably use the group methods - because the group "coordinates" the state of the buttons as a whole. Note that setSelection() isn't quite like a user click in that it doesn't fire a method. Now, in your case you are essentially clearing the selection of the group and ButtonGroup provides a method for that. public void setButton(){ // this method doesn't work
if (button1.isSelected() == true)
button1.setSelected(false);
else if (button2.isSelected() == true)
button2.setSelected(false);
group.clearSelection();
}Note we don't usually write if(foo == true), it's enough to say if(foo).
You will get better and faster help from the Swing forum and it helps everyone if posts are made to the right place. http://forum.java.sun.com/forum.jspa?forumID=57
Similar Messages
-
Please Help: Trouble with nested CASE statement and comparing dates
Please tell me why the query below is always returning the bold null even when the start_date of OLD is greater than or equal to the start_date of NEW.
What I want to do is get the difference of the start_dates of two statuses ( Start_date of OLD - Start_date of NEW) if
1. end_date of NEW is not null
2. start_date of OLD is greater than start_date of NEW
else return null.
select id,
case when max(end_date) keep (dense_rank last order by decode(request_wflow_status,'New',1,0),start_date) is null then
null
else
case when max(decode(status,'OLD',start_date,null)) > max(decode(status,'NEW',start_date,null))
then max(decode(status,'OLD',start_date,null)) - max(decode(status,'NEW',start_date,null))
else
null
end
end result
from cc_request_status where id =1
group by id;Avinash,
Thank you for your help.. Here is a more description of my problem..
Here is a sample of data I have for a table with four columns (id,status,start_date,end_date)
What I need to do is to get difference of the start dates of the maximum available dates, if data is valid. The pseducode is as follows:
IF end_date of New status is null
THEN return null
ELSE
IF start_date of old >= start_date of new
THEN return (start_date of old - start_date of new)
ELSE return null
I used the following query but always return the bold null
select id,
(case when max(end_date) keep (dense_rank last order by decode(status,'new',1,0),start_date) is null then
null
else
(case when max(decode(status,'old',start_date,null)) >=
max(decode(status,'new',start_date,null))
then max(decode(status,'old',start_date,null)) - max(decode(status,'new',start_date,null))
else
null
end)
end) result
from tbl where id =1
Based on the below sample, I expected to get the following result; 14-Mar-07 - 16-Feb-07 which is the difference of the maximum start_dates of the two statuses. However the query is not working.. Please help me.. Thank you..
Id Status start_date end_date
1 new 03-Feb-07 07-Feb-07
1 new 16-Feb-07 21-Feb-07
1 old '10-Mar-07 12-Mar-07
1 old '14-Mar-07 16-Mar-07 -
Please help me with this urgent viewing and editing question for a long video clip.
Hi, I have never used this software before and when I imported a 2 hours and 12 minute video clip of my sister's wedding into the system and added it as one sequence into the program it would only allow me to watch and edit the first 2 minutes.
Why is that and how can I rectify this so that I can watch and edit the whole clip?
Also, can such a long video clip be edited by trimming it and creating transitions where I see fit?
Thanks so much for your advice as I am feeling really stuck right now.
BeckyFirst, the tutorial list in message #3 http://forums.adobe.com/message/2276578 may help
2nd, More information needed for someone to help... please click below and provide the requested information
-Information FAQ http://forums.adobe.com/message/4200840
3rd, did you do the below to be sure your project is correct?
See 2nd post for picture of NEW ITEM process http://forums.adobe.com/message/3776153
-and a FAQ on sequence setting http://forums.adobe.com/message/3804341 -
hey! i have a serious problem coming up which is that i am asked to enter my billing info even for free apps. why should i pay for apps which are free? please help me with this problem! and in the billing info there is pop-up box saying i have accessed my account from didfferent computer but no i have been doing it from the same pc. please help me out.
Tap Settings > General > International. Make sure the Region Format is correct.
As for your Apple ID. Tap Settings > Store > Apple ID > iForgot
Resetting your Apple ID may help.
Congrats on your new iPad !!! -
I just bought this movie "Godzilla 2014" but it won't show in my Movie Library. I closed my Itunes and put it back on again but still won't show up. I checked my purchased list and it shows that I recently bought the movie but when I checked the itunes store it wants to buy the movie again. Please help me with this right away Apple.
Apple Store Customer Service at 1-800-676-2775 or visit online Help for more information.
To contact product and tech support: Contacting Apple for support and service - this includes
international calling numbers..
For Mac App Store: Apple - Support - Mac App Store.
For iTunes: Apple - Support - iTunes. -
HELP!!!! My Hotmail no longer works with Safari v. 5.0.6 and my Imac Leopard operating system 10.5.8. Please help me with any suggestions on what to do. Thank you. I cannot find any new downloads for Safari that work with Leopard. The newest ones only work with Lion. My Firefox browser still works though but I would rather use Safari and cannot access any e-mails or send any e-mails via Safari. This happened about 3 weeks ago and I thought it was just a glitch on Hotmail's site. Now I realize Hotmail must have released an update that no longer works with Leopard 10.5.8. PLEASE HELP ME!!!! Thanks to anyone and everyone who reads this and attempts to help me. I do not know what to do....
Hi Sue,
What exactly happens when trying Safari?
They did change it to Outlook recently, but while not pretty, I can access mine with Safari 4.0 still...
You can also set it up in Mail so you don't need a browser at all if you want. -
Hello, Honestly I just updated my 4s and my iPad 3 to iOS 6 and when try to press on the Music app or the iTunes app it says "cannot connect to iTunes Store" Could you please help me with this thank you so much, Charbel from Lebanon
See these previous discussions help.
App Store Updates (but only Updates)...: Apple Support Communities
Apps suddenly don't update: Apple Support Communities -
I recently upgraded to IOS 10.9.5 and now I can't export anything from final cut Pro X. Could somebody please help me with this?
SSign in to the App Store using the Apple ID that was used to purchase the software.
-
Hi support please help me to sync my ipod and iphone 5 . Since i have installed new itunes version 12 , i am not able to sync to transfer data to my devices through itunes.
I think there is some issue with tunes new version .kindly support ASAP.
Rachna khanna
[email protected]you might need to buy a new cable from the apple store.
-
Could you please help me with the problem. I have macbook with retina with mac os 10.7.4 ann want to update it to mac os 10.7.5. I had been waiting for 2 hours to do it and had tried 3 times but it appeared that it was impossible. What should I do?
You can download the standalone updates:
OS X Lion Update 10.7.5 (Client Combo)
OS X Lion 10.7.5 Supplemental Update -
I tried to downgrade my iCloud and when i did it never refunded me can you please help me with this thank you James
<Personal Information Edited by Host>How did you try to downgrade
(Don't post your telephone number in public places, unless you need more useless phone calls) I will ask for it to be removed. -
i brought a iTunes card and the the code on the back is not there it has faded away can u please help me with this problem
Hi Daniel ...
Try here > iTunes Store: Invalid, inactive, or illegible codes -
I have unlocked my iphone and when tried to upgrade it, i got an error, so i restored it.But i was not able to activate my iphone 3gs now...it is showing a message like ' sim card not found'..please help me with this regard
Try popping out the SIM card and turn off the phone.
Pop in the SIM card once again and turn on the phone, make sure that the SIM card is placed and seated perfectly in the tray!
Tell me how did you unlock your phone!? -
PLEASE HELP ME. Some important emails have gone to an archive mail box and i really need them. Can someone please help me with how to view the archive email box and the emails that are in there?
http://kb.mozillazine.org/Recovering_deleted_mail_accounts
-
I have a red vertical line on the right side of my screen and it will not go away tried restarting my computer and that didn't help at all, please help me with this problem it is kind of annoying
If it's a thin 1 pixel wide vertical line it's highly likely it could be caused by a defective LCD.
One quick basic way to check is to note the position of the line. Then go to System Preferences, Displays, and lower the resolution. If ther line moves it's on the video and the logic board or video card if fitted is likely to be defective. If the line stays in the same position it's likely to be an LCD fault. Either way to have it repaired you'll need to visit an Apple store or AASP.
The worst offender for this problem is the Late 2006 17" iMac. FOC replacement of the LCD used to be covered by a quality program, but it's now ended.
Steve
Maybe you are looking for
-
ILife 08 iWeb 08 - Podcast Not Working HELP!
I may not have explained myself in my last post, so I'll try again. o.k. Who has had a problem with the new 08 stuff? I am not a computer genius and do my podcast in garageband, share it with iWeb, and publish with .mac. I am not good at code and hav
-
Give Discount/Surcharges to PR00
Hi Experts, Please can you explain how to give discount to PR00 base value? For example, currently the pricing logic is PR00 value * quantity = gross value. Any discount or surcharges will be based on this gross value. How to change it to give discou
-
Log shipping is not restoring log files ata particular time
Hi, I have configured log shipping and it restores all the log files upto a particular time after which it throws error and not in consistent sate. I tried deleting and again configuring log shipping couple of times but no success. Can any one tell m
-
Getting BAPI header and library files
Hi, I'm going to develop a job scheduling system that satisfies XBP 2.0 certification requirements. I received some documents of XBP 2.0 from a SAP ICC consultant and reviewed them. Now I'm going to prepare for setting up a development environment an
-
Problems downloading multiple ftp files
Hi community! I'm new to this board, and i've joined because I got a severe problem. I need to download some thousands of files the path of which I'v got stored i an SQLServer Database. So, i'm just running through my db and for every line I download