Using IO to create a Combo Box

Hello,
I have failed to find any examples on how to do the following, and have not yet figured out how to do it msyelf.
I want to add the entire contents of a file containg a list of people's personal numbers and their names to a combo box that is then added to the frame.
Here is the code: -
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class IOCombo extends JFrame
implements ActionListener {
public JButton b1;
public JPanel panel, panel_top, panel_office;
public JFrame frame;
public JLabel officeLabel, personLabel, buttonWorkedLabel;
String OfficeChosen;
String[] Office = {"London", "Paris", "NYC"};
String[] OfficeList;
int[] personalNumber;
public IOCombo() {
frame = new JFrame("IOCombo Test");
panel_top = new JPanel();
panel_office = new JPanel();
panel = new JPanel();
officeLabel = new JLabel("The Office is in ");
personLabel = new JLabel(".");
buttonWorkedLabel = new JLabel(".");
// Exit when the window is closed.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b1 = new JButton("Office");
b1.setVerticalTextPosition(AbstractButton.CENTER);
b1.setHorizontalTextPosition(AbstractButton.LEFT);
b1.setMnemonic(KeyEvent.VK_O);
//Listen for actions
b1.addActionListener(this);
//tooltips for buttons
b1.setToolTipText("Choose an Office and a person and then click to edit that Office's Person.");
JComboBox office = new JComboBox(Office);
office.setSelectedIndex(0);
     office.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {
     JComboBox cb = (JComboBox)e.getSource();
     OfficeChosen = (String)cb.getSelectedItem();
try
whichOffice(OfficeChosen);
catch(IOException ex)
//set layout of all panels and add them to frame.
panel_office.add(officeLabel);
panel_office.add(office);
panel_office.add(personLabel);
panel_top.setLayout(new FlowLayout());
panel_top.add(b1);
panel_top.add(buttonWorkedLabel);
     panel.setLayout(new GridLayout(3,0));
panel.add(panel_office);
panel.add(panel_top);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
public void actionPerformed(ActionEvent e) {
String buttonPressed = e.getActionCommand();
if (buttonPressed.equals("Office"))
/**This is just a test, removed the Dialog class to
manipulate the office*/
buttonWorkedLabel.setText("Worked");
else {
/** How do I set-up the combo box using the Office Person chosen from the
file and allocate it to the frame?*/
public void whichOffice(String OfficeChos)throws IOException{
officeLabel.setText("The Office chosen is: " + OfficeChos);
String s, name ="";
int personalNum;
BufferedReader fr = null;
fr = new BufferedReader(new FileReader (OfficeChos+".txt"));
while ((s=fr.readLine()) != null)
StringTokenizer st = new StringTokenizer (s," ");
personalNum = Integer.parseInt(st.nextToken());
st.nextToken();
name = st.nextToken() + " " + st.nextToken();
personLabel.setText(personalNum + " " + name);
/** This method only works if the file contains person
how should I change this to read everyone in?
I want to add the entire contents of personal number and name
of the file to a combo box that is then added to the frame.
public static void main(String[] args) {
IOCombo iocombo = new IOCombo();
The file I have set-up currently that works is called "London.txt" and it contains: -
1 = John Smith
Cheers in advance,
Richard.

Hi,
Sorry I cannot get the code you provided to work, not sure if its your code or the ways I have tried to implement it. Please can you check into it and if it works give the completed code.
Reprovided code with formating :-)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class IOCombo extends JFrame
                        implements ActionListener {
    public JButton b1;
    public JPanel panel, panel_top, panel_office;
    public JFrame frame;
    public JLabel officeLabel, personLabel, buttonWorkedLabel;
    String OfficeChosen;
    String[] Office = {"London", "Paris", "NYC"};
    String[] OfficeList;
    int[] personalNumber;
    public IOCombo() {
        frame = new JFrame("IOCombo Test");
        panel_top = new JPanel();
        panel_office = new JPanel();
        panel = new JPanel();    
        officeLabel = new JLabel("The Office is in ");
        personLabel = new JLabel(".");
        buttonWorkedLabel = new JLabel(".");
// Exit when the window is closed.
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        b1 = new JButton("Office");
        b1.setVerticalTextPosition(AbstractButton.CENTER);
        b1.setHorizontalTextPosition(AbstractButton.LEFT);
        b1.setMnemonic(KeyEvent.VK_O);
//Listen for actions
        b1.addActionListener(this);
//tooltips for buttons
        b1.setToolTipText("Choose an Office and a person and then click to edit that Office's Person.");
        JComboBox office = new JComboBox(Office);
        office.setSelectedIndex(0);
     office.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                     JComboBox cb = (JComboBox)e.getSource();
                     OfficeChosen = (String)cb.getSelectedItem();
                        try
                            whichOffice(OfficeChosen);
                        catch(IOException ex)
//set layout of all panels and add them to frame.
        panel_office.add(officeLabel);
        panel_office.add(office);
        panel_office.add(personLabel);
        panel_top.setLayout(new FlowLayout());
        panel_top.add(b1);
        panel_top.add(buttonWorkedLabel);
     panel.setLayout(new GridLayout(3,0));
        panel.add(panel_office);
        panel.add(panel_top);
        frame.getContentPane().add(panel);
        frame.pack();
        frame.setVisible(true);
    public void actionPerformed(ActionEvent e) {
        String buttonPressed = e.getActionCommand();
        if (buttonPressed.equals("Office"))
                /**This is just a test, removed the Dialog class to
                 manipulate the office*/
                buttonWorkedLabel.setText("Worked");
        else {
            /** How do I set-up the combo box using the Office Person chosen from the
             file and allocate it to the frame?*/
    public void whichOffice(String OfficeChos)throws IOException{
        officeLabel.setText("The Office chosen is: " + OfficeChos);
        String s, name ="";
        int personalNum;
        BufferedReader fr = null;
        fr = new BufferedReader(new FileReader ("c:\\java\\kjc\\set\\"+OfficeChos+".txt"));
        while ((s=fr.readLine()) != null)
                StringTokenizer st = new StringTokenizer (s," ");
                personalNum = Integer.parseInt(st.nextToken());
                st.nextToken();
                name = st.nextToken() + "  " + st.nextToken();
                personLabel.setText(personalNum + " " + name);
                /** This method only works if the file contains person
                 how should I change this to read everyone in?
                 I want to add the entire contents of personal number and name
                 of the file to a combo box that is then added to the frame.
    public static void main(String[] args) {
        IOCombo iocombo = new IOCombo();
}Cheers,
Richard

Similar Messages

  • Creating "Control Combo Box " Relation with data block

    Hi all dears
    i am switching from C# to oracle developer for joining gulf net software house, i have a problem regarding master detail data
    the senerio is
    "List items" control Filled programatically as under shortly:-
    rg_id := create_group_from_query('myrg', 'select dname a, dname b from dept');
    populate_group(rg_id);
    populate_list('mylist', rg_id);
    using this i fill my combo box during new form instance trigger
    i have created a datablock emp through wizard which can show 10 record.
    now
    Problem 1
    i want to show records on form when user select any dept from combo box.
    Problem 2
    if i create group from query and in select statement is like this "select dname, dpetno from dept" the record group is created successfully but i am unable to populate_list due to different data type colums in record group how i will populate list so that List items Labels are department name and value is department no
    Thanks in advance for persual

    Hi dears all
    I have solved this problem my self
    1. select dept name form combo box and the data block shows the emp's of concern depat
    solution
    create a data block of emp table through wizard
    create its table view and show 10 records
    go to datablock i consider its name "emp" datablock properties
    in Where clause condition specify deptno = : my_combo_box;
    now go to combo box when item changed event
    go_bolck("emp);
    execute_query;

  • Creating a combo box to change graph type

    Hello Gurus,
    I need to create a combo box in a web page to change the graph type used. How would I go about to achieve this?
    Thanks.

    ceate the second combo box , at the palce where i will create the first combo boxAs i see .. u dont require two comboboxes in u r case just have to set the combobox with different ComboBoxModel each time u make a selection.
    in listener event of the combobox change the model with setModel function. You can create new model by
    combo1.setModel(new JComboBox(new Object[]{"opt1","opt2","opt3","opt4"}).getModel());

  • Using Automator to create a text box of certain size

    I'm very new to using automator... in fact I haven't used it at all, but I am wondering if I can use it to create a text box of the same size each type to type in within preview (a PDF document).  Basically I want to click or push something and have a text box be generated that is the same size each time.
    Thanks!

    1. In the Finder actions you will need:
    - Get Specified Finder Items, and point it towards the folder that will contain the movie.
    - Get Folder Contents - to get what's inside the folder.
    - Filter Finder Items - set to filter by 'Name Extension' 'Is equal to' 'mov' and make sure all your video files have the right extension...
    - Open Finder Items - in QT Player - note that this might cause problems if there are multiple files in the folder...
    Then from the QT Player actions:
    - Play Movies.
    2. Save As... Application, then after saving, drag the app into the login items for the user account.
    3. That's going to need some AppleScript, but this thread should get you started:
    http://discussions.apple.com/thread.jspa?threadID=455825&tstart=0
    Ian

  • Can images be used as selections in a combo box in Acrobat 9 Pro?

    Can images be used as selections in a combo box in Acrobat 9 Pro? I only see options for text choices when I look at the combo box properties. Basically, I want to click the drop-down and see images (small logos) from which to choose as opposed to text choices.
    I'm grateful for any thoughts on this.

    Have a look at the PO sample that ships with Designer. It shows the provinces or states based on the country that you choose. Look in the Designer install folder under EN/Samples/Forms/Purchase Order/Dynamic Interactive

  • Can I use an LOV with a Combo Box?

    ... and if so, how?
    This should be easy, but I've been searching for over an hour now and I keep getting instruction on how to do each individually, but not how to put them together for the desired behavior.
    My goal is to have a combo box (single line text field with a drop down arrow) that, when the user clicks the arrow, displays a list populated from a column in the data base and the user selects a value.
    I'm using Oracle 10g2
    Thanks in advance,
    Darren

    Why don't you create a record group and populate that record group into the list item on runtime?
    -Ammad

  • Use only unique values as combo box data provider.

    I have an array collection of objects each of which has a
    property I
    will simply call 'name'. Let us say that this array
    collection contains
    a list of objects with the following name values
    ['George','Fred','George','Ron','Bill','Charlie','Bill','Bill','Percy'].
    I would like to use these names as the data provider of a
    combo box, but
    without the duplicates. What would be the easiest way to
    distill this
    down to an array of unique values to use as this combo box's
    data
    provider in Flex?
    The original array collection was the result of an remote
    object call to
    a cfc that returned a record set from a data store. Is it a
    better
    option to create a new function in this cfc that returns the
    unique list
    I desire, or can I do this easily inside the Flex code since
    I already
    have the complete list?
    TIA
    Ian Skinner

    Untested:
    var aData:Array =
    ['George','Fred','George','Ron','Bill','Charlie','Bill','Bill','Percy'];
    var oCheck:Object = new Object():
    var aUnique:Array = new Array()
    var sValue:String
    for (vari:int=0;i<aData.length;i++) {
    sValue = aData[ i ];
    if (!oCheck[sValue ]) { //is this a unique value?
    oCheck[sValue ] = true; //put this value in the check object
    aUnique.push(sValue)
    Note: if the values contain illegal property name values, yo
    would need to modify this.
    Tracy

  • How do i create a combo-box?

    Dear guys..how do i create a simple combo-box that get populated with data fron the database at run-time? I can create pop-lists , but that is hardcoded and no good to me.
    Kind Regards

    cheers folks..most helpful :)
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by [email protected]:
    Hi, Satnam Bihal
    I think this code will solve your problem.
    DECLARE
    rgid RECORDGROUP ;
    err NUMBER ;
    BEGIN
    :main.dynamic_list := '' ;
    :main.list_value := '' ;
    IF :main.sql_text IS NOT NULL THEN
    CLEAR_LIST('main.dynamic_list') ;
    rgid := CREATE_GROUP_FROM_QUERY('rg', :main.sql_text) ;
    err := POPULATE_GROUP(rgid) ;
    POPULATE_LIST('dynamic_list', rgid) ;
    DELETE_GROUP(rgid) ;
    END IF ;
    END ;<HR></BLOCKQUOTE>
    null

  • Is there a way on a MAC to create a Combo Box Drop Down list with multiple email addresses?

    I'm trying to create a Submit To button on a form that allows me to choose between five different people and their email addresses.
    This one form can be sent to five different people, and if I just want to send to one, how do I program that in a combo box?
    Can anyone please help??

    Yes I believe JavaScript may be the answer because I can't seem to get anything else to work.
    Currently the email will only need to be sent to one recipient at a time.
    I am very unfamiliar with JavaScript and am just starting to dive into it. Would you be able to help me with the coding?
    Thank you this sounds very promising!

  • I have NO scripting experience but am attempting to create "cascading combo box" with two boxes.

    I have copied and edited to the best of my ability several options but keep getting errors, mostly illegal character on line...
    I do not have LifeCycle, merely Adobe Acrobat IX (and a trial version of Acrobat XI PRO) and the extent of my knowledge ends at placing fields, text, etc. . .
    The scenario is as follows:
    On the document, there are two combo boxes
    1- "DeptName"
    2- "Position"
    The goal is to be able to select one of 15 different departments, and based on that selection, choose from between 2 to 15 different positions for that corresponding department.
    Below is what I was hopeful would work, but alas - FAIL!!
    If anyone could assist it would be GREATLY APPRECIATED!
    myDeptNameValues =
    "ADMINISTRATION – RSADMN (8171)",
    "BEVERAGE – RSBEV (8174)",
    "CATERING – RCCAT (8959)",
    "CLUB – RSCLB (8174)",
    "CONCESSIONS – RCCON (8961)",
    "CONCESSIONS – RSCON (8173)",
    "CULINARY – RSKIT (8177)",
    "FACILITIES – RSFAC (6925)",
    "RETAIL – RSRET (8175)",
    "SUITES – RSSTE (8177)",
    "VENDING – RSVND (8173)",
    "WAREHOUSE – RSWHS (8173)"
    this.getField("DeptName").setItems(myDeptNameValues);
    var DeptData =
    ADMINISTRATION – RSADMN (8171):["Teller","Security"],
    BEVERAGE – RSBEV (8174):["Bartender","Barback"],
    CATERING – RCCAT (8959):["Banquet Server",”Banquet Captain"],
    CLUB – RSCLB (8174):["Cashier","Counter","Cook","In Seat Server","Runner","Stand Manager"],
    CONCESSIONS – RCCON (8961):["Counter","Cashier","Cook","Runner","Beer Attendant/SMC","Stand Lead","Supervisor"],
    CONCESSIONS – RSCON (8173):["Counter","Cashier","Cook","Runner","Beer Attendant/SMC","Stand Lead","Supervisor"],
    CULINARY – RSKIT (8177):["Cook 1 – Entry Level","Cook 2 – Advanced Level","Cook 3 – Lead Cook","Kitchen Supervisor","Steward"],
    FACILITIES – RSFAC (6925):["Lead – Blower/Press","Cleaning Services Worker"],
    RETAIL – RSRET (8175):["Warehouse","Supervisor","Warehouse Supervisor","Vendors/Hawkers","Senior Supervisor","Associates"],
    SUITES – RSSTE (8177):["Suite Attendant","Ice Cream Cart Attendant","Runner","ReOrder Clerk","Suite Captain","Pantry Supervisor"],
    VENDING – RSVND (8173):["Vendor","Vendor Filler","Alcohol Compliance Supervisor","Auditor","Level Supervisor","Senior Supervisor"],
    WAREHOUSE – RSWHS (8173):["Runner","Supervisor"]
    function SetFieldValues(cDeptName)
    this.getField("Position").setItems(DeptData[cDeptName]);
    The above code was placed in the document script.  Within the format area of the "DeptName" box, I have the following code placed in the keystroke script.
    if( event.willCommit )
    if(event.value == "")
    this.getField("box2").clearItems();
    else
    SetFieldValues(event.value);
    I have spent the past four days, more than 18 hours in the last two alone trying to nail this down and I can't explain how completely defeated I feel, not to mention frustrated.
    Again, thanks for your help!!

    I suppose I am not meant to figure this out.  I am trying my absolute hardest to accomplish compiling this document without having to resort to asking someone to do it for me as I have noticed in a few other threads, but it just seems to get more frustrating.  I have accomplished the first thing I set out to do and I completely appreciate your assistance with that.  My issue now is that i have other text fields I want to automatically fill based on the selection of the very same DeptName combo box.  I can make the cascading/dependent box work with the initial DeptName box, or all the additional text fields with the DeptName box, but cannot seem to accomplish having them work together.  I have been working daily, reading blogs/forums, watching videos all in an effort to complete this before it's needed on Feb. 2. 
    Is it possible to make 7 text fields and a combo box(B) fill based on the selection of a separate combo box (A), and then have 5 more text fields automatically fill based on the selection from the secondary box (B)?  I can make it all happen individually, meaning only the text fields for one box or the combo box (A to b) but not in conjunction.
    http://1drv.ms/1GDpESS
    This is the file, if it helps to see what I'm hoping to accomplish

  • How can I create a multi-line combo box?

    I am using Adobe Acrobat Pro 9 and I am trying to create a multi-line combo box on my fillable form.  At the bottom of this form/letter I would like to have a several paragraps that the user can choose from, but it's only allowing me to enter one line at a time.  Any help??

    Hi, Did you find the answer to this? I'm looking to create a combo box with multi-lines

  • Trying to filter an entire database using a combo box or text box

    Hi,
    I am looking to create a combo box with rows vice columns, then I would like to create a macro or some for form of filter that gives me the option to search within each or all of the selections.
    I have created a search function (using a textbox and the button features) that allows me to search for anything in my database using applyfilter. The problem that I ran into with this was that when I hit the might work, but only the first line worked.
    So I tried to use a combination box to create a filter of the fields that I want to view for the particular search I need, but I want to select row headers vice columns of information. For example if I have five fields of: Last Name, First Name, SSN, Document
    number and Unique ID.
    I want a combination box to show the following field header when I click the drop down option.
    (Last Name
    First Name
    SSN
    Documentation Number
    Unique ID)
    Then I would to apply a macro filter feature for files within theses individual fields. I am just getting started in VBA and using Macros, so any help would be awesome!!
    If I am too far off target please direct me back, I tend to over think things.
    Thanks in Advance

    Dirk Goldgar, I tried to you use the suggested method you gave me. Part of the problem I was having was that I wanted to view the field list, which I now know is very possible thanks to you, but only wanted it to show as one single list of fields.
    So took the information you gave me and went on to create a list box instead. I later found out why this was not working either.
    In what way was it not working?  You can do the same thing with a list box as I described for a combo box.
    I have relationships of tables attached.
    I don't understand what you mean by that last statement, or how it's relevant to the discussion.  Do you mean you have multiple different tables that you might want to filter?  So you would need to either (a) first need to select a table from a
    list of tables in your database, and only then select a field in that table, or else (b) have a table listing all the data elements you might want to search, with the table and field name of each, and base a list box on that -- then the code to search would
    know what table to select from, as well as what field to filter on.
    So this info that you provided was very helpful. I will continue to go through the link you provided.
    So I can quickly sum up what I need:
    1. A dropdown box that allows me to search any Field List
    2. A textbox that allows me to type in the searchable information for that particular field.
    3. Or some way to build a filter function for the whole list, with a textbox to search the key words.
    This is all still a bit unclear to me, because I don't know whether you want to search a particular table, or any of many possible tables in the database.
    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

  • Dependent combo boxes using webservice

    Hi All,
    I'm trying to create a depended combo boxes using af:selectOneChoice, using webservice datacontrol. When i try to change the value of the first combo box which has hard coded values (eg. Continent), The depended combo box (eg.Country) is empty. (which is returned via webservice) When i again change the value of the first combo box, I get the corresponding values(Countries) generated. The very first time when a value is selected is not binded to the model. Why is this happening and how to overcome this issue. I tried using the value change listener and assigned the current value to binding but there was no change in the behaviour.

    Thanks for your response Frank. The Sample worked fine. But when i try to implement the same i ran into issues.
    First, I created a combo box for continents and a managed bean.
    <af:selectOneChoice label="Region" id="soc1" autoSubmit="true"
                                  valueChangeListener="#{locateBean.setRegion}">
                <af:selectItem label="Asia" value="Asia" id="si3"/>
                <af:selectItem label="Europe" value="Europe" id="si2"/>
                <af:selectItem label="NA" value="NA" id="si1"/>
              </af:selectOneChoice>Then I created a combo box for countries using the webservice data control.
              <af:selectOneChoice value="#{bindings.Country.inputValue}"
                                  label="Country"
                                  required="#{bindings.Country.hints.mandatory}"
                                  shortDesc="#{bindings.Country.hints.tooltip}"
                                  id="soc2" partialTriggers="soc1">
                <f:selectItems value="#{bindings.Country.items}" id="si4"/>
              </af:selectOneChoice>In the managed bean as
        public void setRegion(ValueChangeEvent event) {
            this.region = (String)event.getNewValue();
        }1. When i run and select an continent, the values are not getting populated in the country combo box. If i refresh the page or select another value for the continent, then its is getting populated.
    2. When i tried to execute the operation manually at pagedef on value change event,
            OperationBinding operBinding = getBindings().getOperationBinding("GetCountryList");
            operBinding.execute();I'm getting an warning as <FacesCtrlListBinding> <getInputValue> ADFv: Could not find selected item matching value Afghanistan of type: java.lang.String in the list-of-values.Why the value binded to the managed bean or model is not getting updated for the first time. Is this the expected behavior.

  • Having trouble with combo box in action script 3

    I have created a combo box in action script 3.0 and have some things working and others not. I am creating a store for shirts, caps, etc..... so need different things and rates. Can anyone help me?
    [email protected]

    Creating a STORE for my website and used combo buttons with types of shirts for one button, 2nd button with color, and third with sizes.
    Using Action Script 3.0 making these work and having trouble.
    HELP meaning if you can connect to my computer remotely and see where my problem is. I am happy to pay if works.

  • Programmatically Change Combo Box List

    Hello,
    I searched heavily on these forums and found answers that were close, but I cannot quite figure out the following:
    I have a large number of individual RF assemblies, most having the same test requirements.  My plan is to create a combo box (or similiar) from which the assembly number can be selected.  This box will then provide a numeric value to a case structure, which will then provide the need test parameters and what not.
    I know the combo box list can be populated with a property node and the property node fed by an array.  It is my hope to be able to put this info in a spreadsheet file that can be updated as necessary and then imported into the VI at run time.  Therein lies my problem.
    Using the strings and value[ ] property, I can make the combo box work correctly, but I cannot figure out how to import the spreadsheet into the proper format to feed the property node.  I've tried various spreadsheet import schemes offered on these forums, but none quite hit it.  I've tried to figure it out on my own, but I'm just spinning my wheels.
    Any help would be appreciated.
    Thanks.
    Attachments:
    PullDown_Module.vi ‏30 KB

    Hello,
    I've attached a VI that I think will help you.  I actually used the Index & Bundle Cluster Array function, which I don't think I've ever used before.    Anyway, this function gets the two arrays of strings from my tab-delimited text file and manipulates them into an array of clusters containing two strings each, which is the data type required by the StringsAndValues[] property of the Combo Box:
    I hope this gets you started in the right direction.  Good luck!
    -D
    Message Edited by Darren on 03-17-200602:18 PM
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman
    Attachments:
    Combo_Box_Screenshot.jpg ‏100 KB
    Combo_Box.vi ‏27 KB
    data.txt ‏1 KB

Maybe you are looking for