How to Figure out what checkboxes are selected upon a button click...
If I have a panel with some JCheckBoxes and a JButton, how can I figure out what checkboxes are selected upon the button click? If I add an actionlistener to the button, inside actionPerformed, how would I know what checkboxes are selected? One caveat is that the name and number of these checkboxes are dymanically chaing based on a configuration file so I do not know what the names of these check boxes are.
Any help/code sample would be appreciated.
Here's one of several different ways to do it. It attaches an ItemListener to each checkBox. When the checkBox is clicked, it is either added or removed from a List of selected items. Clicking the button will show you the selected items.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class CheckBoxTest extends JFrame
JCheckBox chkChoice1 = new JCheckBox("English");
JCheckBox chkChoice2 = new JCheckBox("French");
JCheckBox chkChoice3 = new JCheckBox("German");
JCheckBox chkChoice4 = new JCheckBox("Italian");
JTextArea txaDisplay = new JTextArea(5, 20);
JButton btnShow = new JButton("Show Selected Items");
ArrayList <JCheckBox>choices = new ArrayList<JCheckBox>();
public CheckBoxTest()
super("");
setDefaultCloseOperation(EXIT_ON_CLOSE);
chkChoice1.addItemListener(new CheckBoxListener(chkChoice1));
chkChoice2.addItemListener(new CheckBoxListener(chkChoice2));
chkChoice3.addItemListener(new CheckBoxListener(chkChoice3));
chkChoice4.addItemListener(new CheckBoxListener(chkChoice4));
btnShow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
txaDisplay.setText("");
for (JCheckBox jcb : choices)
txaDisplay.append(jcb.getText() + "\n");
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(chkChoice1);
buttonPanel.add(chkChoice2);
buttonPanel.add(chkChoice3);
buttonPanel.add(chkChoice4);
JScrollPane scroll = new JScrollPane(txaDisplay);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
JPanel dataPanel = new JPanel();
dataPanel.add(btnShow);
dataPanel.add(scroll);
Container c = getContentPane();
c.setLayout(new BorderLayout());
c.add(buttonPanel, BorderLayout.NORTH);
c.add(dataPanel, BorderLayout.CENTER);
pack();
public static void main( String[] args )
CheckBoxTest frame = new CheckBoxTest();
frame.setVisible(true);
class CheckBoxListener implements ItemListener
JCheckBox checkBox;
public CheckBoxListener(JCheckBox checkBox)
this.checkBox = checkBox;
public void itemStateChanged(ItemEvent event)
if (checkBox.isSelected())
choices.add(checkBox);
else
choices.remove(checkBox);
}Or, you could just maintain all the checkboxes in a Collection ahead of time. When the Show button is selected, simple query isSelected() on each item.
Again, there are several different ways.
Similar Messages
-
How to figure out which tables are using Extensible Optimizer?
Hi guys,
I'm sure that there're several tables those are associated with Extensible Optimizer in my database, I can also find the Extensible Optimizer relevant type and the implementation of interface functions ODCIGetInterfaces, ODCIStatsTableFunction.
I'm curious to know is there a way to figure out which tables are associated with this Extensible Optimizer, does anyone have any clues?
Database: oracle 11.2
Thank you in advance.Hi,
Can you please check the below link.It may help you:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28425/ext_optimizer.htm
Best regards,
Rafi.
http://rafioracledba.blogspot.com -
How to find out what applications are consuming a service in SR
Hi,
How can one find out what or which all applications are consuming a particular service from Service Registry?
There is tab called Used By when we select a service from service registry. But it always shows empty.
Any help is much appreciated.
Best Regards,
ShivaProblem got resolved by myself.
It will be reflected in Used By tab once an application is consumed from SR,
Thanks.
Best Regards,
Shiva -
Organization: Figuring out what photos are organized into albums
I can't seem to work out a straightforward way of organizing photos once I import them into Aperture 1.5. I shot 2Gb of shots today and imported them. As I start to create Albums within my Project, I drag them to their appropriate places. But sometimes I'll miss one or get interrupted by a phone call, etc.
Or I'll start out with five albums of different categories, say Front Façade, Interior Lobby, etc. (architectural shots). Then I realize that I've got so many Stair shots that I want another album just to keep those organized. But then some shots are stairs in the lobby and I can't figure out if I've put them in one of the albums or neither. I have to scroll through tons of shots to figure it out. It's always confusing.
Has anyone figured out a good workflow for bringing photos in and ensuring that each actually winds up in an album?
PowerBook G4 17 Mac OS X (10.4.8)I've finally figured out the solution to tracking which images have been 'assigned'...it's through the use of keywords and smart albums, not regular albums. It also lets you know whether you've missed assigning any images:
Create a Smart Album called "No Keywords". In the Search HUD that comes up when you do this, click on the "+" drop-down menu and select "IPTC". Click the checkbox next to the new IPTC line that's added to your search criteria, and select "Keywords" and "is empty" from the two drop-down menus. By using this or the "is not empty" or the other criteria in different/multiple combinations (you can add the IPTC line more than once), you can sort for anything.
Once you've set this up, start applying keywords to images. They will 'disappear' from this Smart Album. When the Smart Album is empty, you've assigned a keyword to everything. Keep this Smart Album in case you import other images or to check periodically to see if any images have been 'orphaned'.
Then use your keywords list to create Smart Albums that have keywords singly or in combination. I do this now and don't create regular albums at all.
One great piece of advice I've come across and will repeat here is that it's REALLY best to create ALL your keywords BEFORE you start applying them. In my first couple of projects I created them on the fly and realized that they were not perfect, started modifying, realized that some images needed more specificity, etc. Simply put, I made a mess. Now as I scan through an imported shoot I create the keywords first. Then I apply all the keywords I've made before creating any new ones or renaming ones I created in the first round.
Only then, once all the above-mentioned Smart Albums are created, might I add or adjust keywords. At this point it won't throw a wrench into the works and make me lose my bearings.
I'll continue to improve my workflow, but this finally works well for me, and it's pretty time-efficient.
Anyone have any gems to add to this thread before I mark it answered?
Message was edited by: Erick Mikiten -
How to find out what modules are used
In /etc/rc.conf there are a lot of modules that are loaded that don't need to be, like modules related to OSS. Is there some command that'll show me what modules are being used at the moment and/or what they do?
Yes Thinkpad FTW! Back on topic; so there are three columns: Module, Size and Used By. In the used by column what do the different numbers mean?
I ran "lsmod | less" to be able to view each individual one. (That "| less" part is really useful)
Last edited by jordanwb (2008-08-07 01:59:15) -
HT2731 They ask me about security questions, how do I figure out what they are?
How do I buy an app? It won't allow me with out security answers
See my User Tip for some help: Some Solutions for Resetting Forgotten Security Questions: Apple Support Communities.
Send Apple an email request for help at: Apple - Support - iTunes Store - Contact Us
Call Apple Support in your country: Customer Service: Contacting Apple for support and service -
How to find out what products are installed 10G
I have been getting questions lately "Is OLAP installed, locator... " in 10G, normally
there are tables sys tables that tell generally whats installed but not specifically. Then
in the 11G enterprise manager I saw the database configuration pack that comes
with enterprise manager that really defines -> whats installed, the patch level -> basically
everything... So my question is are there any system tables, stored procedures, or packages that
would give me this information in 10G without having to install the database configuration
pack into a 10G enterprise manager.
thanksYou can query dba_registry for this information.
SQL> col comp_name format a40
SQL> select comp_name, version, status from dba_registry;
COMP_NAME VERSION STATUS
Oracle Database Catalog Views 10.2.0.4.0 VALID
Oracle Database Packages and Types 10.2.0.4.0 VALID
Oracle Workspace Manager 10.2.0.4.3 VALID
JServer JAVA Virtual Machine 10.2.0.4.0 VALID
Oracle XDK 10.2.0.4.0 VALID
Oracle Database Java Packages 10.2.0.4.0 VALID
Oracle Expression Filter 10.2.0.4.0 VALID
Oracle Data Mining 10.2.0.4.0 VALID
Oracle Text 10.2.0.4.0 VALID
Oracle XML Database 10.2.0.4.0 VALID
Oracle Rules Manager 10.2.0.4.0 VALID
Oracle interMedia 10.2.0.4.0 VALID
OLAP Analytic Workspace 10.2.0.4.0 VALID
Oracle OLAP API 10.2.0.4.0 VALID
OLAP Catalog 10.2.0.4.0 VALID
Spatial 10.2.0.4.0 VALID
Oracle Enterprise Manager 10.2.0.4.0 VALID
17 rows selected. -
How to find out what iviews are using a particular system
EP NW2004 SP 17
We are trying to see which iviews are associated with a particular system. I've tried using Content Admin -> Multiiple property Replacement. I add our corporate folder to the 'Selected Objects' -> click next. I then select 'iview' then 'system'. I then select radio button 'search objects by property value' and enter current value of the system in quest and new value with the same system in question. I get like 1,400 hits and the list can not be displayed.
Thanks in advance
-- SteveHi,
this was a really good idea. Since the list is so big, I could think of one other very simple way. Why don't you try to export the complete PCD content as a XML (via the [XML Content and Actions|http://help.sap.com/saphelp_nw70/helpdata/en/93/28f999daa6434a845da6bf9ab5072c/frameset.htm].) In the resulting file you should also be able to search for the system alias and from there get the iView (with the complete PCD path).
Of course there is certainly a way to develop some code which can do the same for you.
Regards,
Holger. -
How to figure out what X-Fi I have? (not n00b question)
I need some help guys as I cannot get the sound working in this prototype notebook that I have. I know for a fact that it has an X-Fi in it and I can see the 4 ports on the left side. The problem is that I have no clue what X-Fi it is and I have downloaded all of the different versions of the software and tried to install it with no luck. The problem is I cannot open the laptop as they used a bunch of different kinds of screws so one would need a plethora of different heads not normally found in screw driver sets to open it.
Any clue on how to go about this?Tried looking up the specs of the laptop on the manufacturer's site to see just what it has?
Mott wrote:
?I know for a fact that it has an X-Fi in it and I can see the 4 ports on the left side.
Don't be too sure about that. Probably find it has some Realtek or ADI based sound card built in, and just uses some of teh X-Fi software (also known as "X-Fi MB). Four ports on the side don't mean much either, just means the laptop can connect and output 5. sound over the analogue connections. -
I have a big Project and I would like to run a VI that would check the required toolkits for my application and also check if those toolkits are indeed installed on my PC.
Thanks for your helpWhen your Project is open, you can see some of the Dependencies, other VIs associated with the VIs listed in your Project. This can include VIs that are in the Physical folder containing the Project but not in a Project Virtual folder, VIs in libraries, including .llbs, vi.lib, and user.lib, .dll files (from NI and others) referenced by items in the Project, and possibly other things. These are items that it finds on your current machine, and that you would need if you moved your code to another computer.
When you load one of the VIs in your Project into memory, it will do a further search to locate all of the functions that it uses, raising an Error condition if one is not found (sometimes due to a missing Driver, for example). A trick that I like to use during Development is to create a "Tree" VI that contains a copy of every VI in my Project. If I open the Tree, and any VI makes a call on a "missing function", I will have a Broken Arrow, and can use the Error reporting to find the Missing Link.
Bob Schor -
Figuring out which JRadioButton is selected
Hey guys. I have a simple program that calculates tempurature in Fahrenheit, Celcius and Kelven.
There are 6 Radiobuttons in a ButtonGroup. I need to know how to get which radiobutton is selected.
Here is my code....I already have an action listener for the buttons that runs the code to do the calculations and display the answer, I just need to know how to figure out which radiobuton is selected.
Thanks!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class DegreeConverter extends JFrame{
JLabel lblFah, lblConversion,lblShowConversion;
JTextField getFah;
JButton btnConvert;
JRadioButton btnFahToCel, btnFahToKel,
btnCelToFah,btnCelToKel,
btnKelToFah, btnKelToCel;
ButtonGroup radioGroup;
public DegreeConverter(){
super("Degree Converter");
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JFrame.setDefaultLookAndFeelDecorated(true);
Container container1 = getContentPane();
SpringLayout layout = new SpringLayout();
container1.setLayout(layout);
lblFah = new JLabel("Enter Temperature:");
container1.add(lblFah);
getFah = new JTextField(5);
container1.add(getFah);
lblConversion = new JLabel("Conversion Answer:");
container1.add(lblConversion);
lblShowConversion = new JLabel("...");
container1.add(lblShowConversion);
btnConvert = new JButton("Convert");
btnConvert.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
String strFah = getFah.getText();
double dblFah = Double.parseDouble(strFah);
lblShowConversion.setText(Double.toString(convertDegrees(dblFah)));
container1.add(btnConvert);
btnFahToCel = new JRadioButton("Fahrenheit To Celcius", true);
container1.add(btnFahToCel);
btnFahToKel = new JRadioButton("Fahrenheit To Kelvin", true);
container1.add(btnFahToKel);
btnCelToFah = new JRadioButton("Celcius To Fahrenheit", true);
container1.add(btnCelToFah);
btnCelToKel = new JRadioButton("Celcius To Kelvin", true);
container1.add(btnCelToKel);
btnKelToFah = new JRadioButton("Kelvin To Fahrenheit", true);
container1.add(btnKelToFah);
btnKelToCel = new JRadioButton("Kelvin To Celcius", true);
container1.add(btnKelToCel);
radioGroup = new ButtonGroup();
radioGroup.add(btnFahToCel);
radioGroup.add(btnFahToKel);
radioGroup.add(btnCelToFah);
radioGroup.add(btnCelToKel);
radioGroup.add(btnKelToFah);
radioGroup.add(btnKelToCel);
//layout for btnFahToCel
layout.putConstraint(SpringLayout.WEST, btnFahToCel,
5,
SpringLayout.WEST, container1);
layout.putConstraint(SpringLayout.NORTH, btnFahToCel,
5,
SpringLayout.NORTH, container1);
//layout for btnFahToKel
layout.putConstraint(SpringLayout.WEST, btnFahToKel,
5,
SpringLayout.WEST, container1);
layout.putConstraint(SpringLayout.NORTH, btnFahToKel,
5,
SpringLayout.SOUTH, btnFahToCel);
//layout for btnCelToFah
layout.putConstraint(SpringLayout.WEST, btnCelToFah,
5,
SpringLayout.WEST, container1);
layout.putConstraint(SpringLayout.NORTH, btnCelToFah,
5,
SpringLayout.SOUTH, btnFahToKel);
//layout for btnCelToKel
layout.putConstraint(SpringLayout.WEST, btnCelToKel,
5,
SpringLayout.WEST, container1);
layout.putConstraint(SpringLayout.NORTH, btnCelToKel,
5,
SpringLayout.SOUTH, btnCelToFah);
//layout for btnKelToFah
layout.putConstraint(SpringLayout.WEST, btnKelToFah,
5,
SpringLayout.WEST, container1);
layout.putConstraint(SpringLayout.NORTH, btnKelToFah,
5,
SpringLayout.SOUTH, btnCelToKel);
//layout for btnKelToCel
layout.putConstraint(SpringLayout.WEST, btnKelToCel,
5,
SpringLayout.WEST, container1);
layout.putConstraint(SpringLayout.NORTH, btnKelToCel,
5,
SpringLayout.SOUTH, btnKelToFah);
//layout for lblFah
layout.putConstraint(SpringLayout.WEST, lblFah,
15,
SpringLayout.EAST, btnFahToCel);
layout.putConstraint(SpringLayout.NORTH, lblFah,
5,
SpringLayout.NORTH, container1);
//layout for getFah
layout.putConstraint(SpringLayout.WEST, getFah,
5,
SpringLayout.EAST, lblFah);
layout.putConstraint(SpringLayout.NORTH, getFah,
5,
SpringLayout.NORTH, container1);
//layout for lblConversion
layout.putConstraint(SpringLayout.WEST, lblConversion,
22,
SpringLayout.EAST, btnFahToKel);
layout.putConstraint(SpringLayout.NORTH, lblConversion,
5,
SpringLayout.SOUTH, lblFah);
//layout for lblShowConversion
layout.putConstraint(SpringLayout.WEST, lblShowConversion,
5,
SpringLayout.EAST, lblConversion);
layout.putConstraint(SpringLayout.NORTH, lblShowConversion,
5,
SpringLayout.SOUTH, lblFah);
//layout for btnConvert
layout.putConstraint(SpringLayout.WEST, btnConvert,
15,
SpringLayout.EAST, btnFahToCel);
layout.putConstraint(SpringLayout.NORTH, btnConvert,
5,
SpringLayout.SOUTH, lblConversion);
//layout for container
layout.putConstraint(SpringLayout.EAST, container1,
50,
SpringLayout.EAST, getFah);
layout.putConstraint(SpringLayout.SOUTH, container1,
5,
SpringLayout.SOUTH, btnKelToCel);
pack();
setVisible(true);
}// end constructor
public static void main(String args[]){
DegreeConverter application = new DegreeConverter();
public double convertDegrees( double fah){
//currently there is only one calculation here.. I need to figure out
//how to get which radiobutton is selected so i can do a select case
//or if/else here to do the appropriate calculations.
DecimalFormat twoDigits = new DecimalFormat("00");
String celcius;
double returnCelcius;
celcius = twoDigits.format(5.0/9.0 * (fah - 32));
returnCelcius = Double.parseDouble(celcius);
return returnCelcius;
}//end convertDegrees
}//end classSwing related questions should be posted in the Swing forum.
1) Test each button
If (button1.isSelected() )
else if (button2.isSelected() )
.... -
I keep getting the message saying that my start up disk is nearly full and I have been deleting as many files as I can but now I find that actually it isn't my photos which I thought it might be, I have no music, videos or movies downloaded and just a small amount of document files. It seems that I have 91.56 GB of files in 'other' does anyone know what they might be and how I find out what they are?
ThanksSee here for answer about what is taking up space:
http://pondini.org/TM/30.html
and here:
http://pondini.org/OSX/DiskSpace.html
Seen in your "about this MAC" under storage as "OTHER -
I cannot figure out what the "other" is that is taking up space on my iPOD.
Please help! I am in the process of burning my songs to my iPOD and I noticed when I synced it up that I had alot of orange, "other" stuff taking up space. I have a few television shows and am building up my music files. I cannot figure out what the "other" is. When I clicked the tab for photos, it had 23 photos that it pulled from My Pictures. However, I played around with the settings and it said under "photos," (0). However, it still has space that it is taking up.
I have alot of music to download and I don't want to have 5.38 bytes of used up space for which I don't know what it is.
Thanks!
-JoshOther can be album artwork, contacts, notes etc. If you feel that the Other is being incorrectly reported you could try restoring your iPod. Just be aware that restoring will erase the hard drive, reload the software and put it back to default settings, so if you have songs on your iPod that aren't on iTunes you will lose them if you have no back up. Once the restore is complete follow the on screen instructions and it should connect to iTunes and give you a prompt to automatically update your library onto the fresh installation. If you want to update manually or using selected playlists choose no and it will default to manual mode and you can choose whatever setting you like: Restoring iPod to factory settings with iTunes 7
-
How do I change the size of the tools and the text for the menus in Photoshop? I need a magnifying glass in order to make out what they are.
Okay, I've figured it out, so I'm going to answer my own question in hopes that it may help anyone else that would like to actually be able to see what they're doing when using Photoshop CC 2014 on a high resolution screen.
1. Open Photoshop.
2. Select Preferences from the Edit Menu, then select General.
3. Change the HUD Color Picker to Hue Strip (Medium).
4. Select Interface from the Preferences menu on the left side of the dialog box.
5. Change the UI Font Size to Large in the Text area of the Preferences dialog box.
6. Select Experimental Features from the Preferences menu on the left side of the dialog box.
7. Select Scale UI 200% for high-density displays (Windows only).
8. Click on OK, then Exit/Quit Photoshop.
9. Open Photoshop and everything should be readable. -
How do i find out what devices are authorised on my apple ID?
I have just bought a new iMac and want to get all my itunes library etc on it. However, apparently i have reached my limit of 5 authorisations, which is entirely possible as I have had a number of iphones, Macair and ipads, some of which I either no longer own or are no longer functioning. How do I find out what devices are authorised and then deauthorise any that I don't use any more - given that they may not even work!
Welcome to the Apple Community.
You can't de-authorise just the computers you no longer have access to.
Your only option is to de-authorise all your computers and then re-authorise those you wish to be authorised. You can do this by logging into your account settings in iTunes on your computer (Store > View My ID) and selecting the option to de-authorise all.
Please note however, you are only permitted to do this once in each 12 month period, therefore you would be better de-authorising your computers before you lose access to them. you can do this from the 'Store' menu in iTunes.
Maybe you are looking for
-
Connection from SAP to our systems involving 2 saprouters
connection from SAP to our systems involving 2 saprouters we have 1 saprouter inside a dmz and another for connecting to our systems. we are guessing that this is possible SAP (sapserv2) - SNC----> saprouter1 (DMZ, SNC connection) - > saprouter2 (P *
-
How can I open an app from an e-mail link that is associated with link.
I get e-mails with links in them all the time (from forms, online shopping, etc). Some of those links are for websites that have an iphone app associated with them (especially forums). When I click on the link it tells me as much, and if I click "o
-
Execute link is not working in Web report
Friends, " Execute" link is dead in web my report. And also the selection screen is blank for style sheets. Do you have any idea about the cause? Joe
-
Can we make an App always open in Full Screen?
Is there a way to make certain Apps (ie: Safari & iTunes) always open in Full Screen as default?
-
How do i change font size permantly and where do i find this?
Where /how do i change font size permantly and where do I find this in the OS?