Custom Combo Box. Error # 2025

package files{
          import flash.display.MovieClip;
          import fl.data.DataProvider;
          import fl.controls.ComboBox;
          import flash.text.*;
          import flash.display.Sprite;
          import flash.filters.*
          public class CustomComboBox extends MovieClip {
                    public var xLoca:Number;
                    public var yLoca:Number;
                    public var dataProvider:DataProvider;
                    public var cboClip:MovieClip;
                    public function CustomComboBox(xLoca:Number, yLoca:Number, dataProvider:DataProvider, prompt:String = "Select") {
                              cboClip = new MovieClip;
                              this.xLoca = xLoca
                              this.yLoca = yLoca
                              this.dataProvider = dataProvider;
                              var typeTextFormat:TextFormat = new TextFormat();
                              typeTextFormat.color = 0x333333;
                              typeTextFormat.size = 11;
                              typeTextFormat.font = "Verdana";
                              var menu1:ComboBox = new ComboBox();
                              cboClip.addChild(menu1);
                              var typeButton:Sprite = new Sprite();
                              menu1.addChild(typeButton);
                              typeButton.graphics.beginFill(0xCCCCCC);
                              typeButton.graphics.drawRect(0, 0, 109, 34);
                              typeButton.graphics.endFill();
                              typeButton.alpha = 0.75;
                              typeButton.filters = [new DropShadowFilter(3,120,0x000000,0.5,0,0,1,1,false,false,false)];
                              var dropButton:Sprite = new Sprite();
                              dropButton.graphics.beginFill(0x99CCFF);
                              dropButton.graphics.drawRect(0, 0, 109, 34);
                              dropButton.graphics.endFill();
                              dropButton.alpha = 0.75;
                              dropButton.filters = [new DropShadowFilter(3,120,0x000000,0.5,0,0,1,1,false,false,false)];
                              menu1.dropdown.addChild(dropButton);
                              menu1.setStyle("upSkin", typeButton);
                              menu1.setStyle("overSkin", typeButton);
                              menu1.setStyle("downSkin", typeButton);
                              menu1.setSize(109, 34);
                              menu1.dropdown.setRendererStyle("upSkin", dropButton);
                              menu1.dropdown.setRendererStyle("overSkin", dropButton);
                              menu1.dropdown.setRendererStyle("downSkin", dropButton);
                              menu1.dropdown.setSize(109, 34);
                              menu1.textField.setStyle("textFormat", typeTextFormat);
                              menu1.dropdown.setRendererStyle("textFormat", typeTextFormat);
                              menu1.move(xLoca, yLoca);
                              menu1.prompt = prompt;
                              menu1.dataProvider = dataProvider;// constructor code
                              addChild(cboClip);
Running the class above with the code below. At first everything works fine, but when you select something and then make a change you get
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
          at flash.display::DisplayObjectContainer/removeChild()
Does anyone have any ideas why?
var dp:DataProvider = new DataProvider();
dp.addItem( { label: "Some Data", data: "Some" } );
dp.addItem( { label: "More Data", data: "More" } );
dp.addItem( { label: "Way More Data", data: "Way More" } );
dp.addItem( { label: "No Data", data: "None" } );
var c:CustomComboBox = new CustomComboBox(50, 50, dp, "How Much Data?");
addChild(c)

The error is indicating a problem with a removeChild() method call, and none of the code you show has that as far as I can see.  So you probably need to look elsewhere for the problemed code.

Similar Messages

  • Custom Combo box

    Dear all,
    If any one developed custom combo box in flash 7. Pls share
    ur files for reference... Urgently needed for me..help me pls
    Thanks
    thil

    It is certainly possible.
    You've got to decide whether you want to try and change the functionality of JComboBox to do it, though. This may seem the most straightforward first step but may not be the most appropriate; are you really talking about a control for selecting a single item from a list? Do you need the ability to edit the selected value directly?
    If you're not after these sorts of things then it may be quicker simply to create a custom component that shows a popup menu when you click a button, for example.
    Getting this to look a bit like a combo box wouldn't be too hard for most look and feel implementations.
    If you're sure you're really after a JComboBox for this functionality then there are various approaches that can be tried.
    Hope this helps.

  • Combo box , error type !

    Hello,
    I've got an error I can't find since 2 days ! I'm trying to build a simple combo box in which there are some data from my database . It's to deploy a process under jBoss jBPM but the error is a JSF one :
    Here is my JSF form code :
        <jbpm:datacell>
          <f:facet name="header">
            <h:outputText value="Produit desire: "/>
          </f:facet>
           <h:selectOneMenu value="#{genList.value}">
                <f:selectItems value="#{genList.items}" />
           </h:selectOneMenu>
        </jbpm:datacell>Then, here is my genList.java :
    public class genList {
         private String value="";
         private Connection conn;
         public genList() {}
         public String getValue() {
              return value;
         public void setValue(String value) {
              this.value = value;
         public Collection getItems() {
              Collection items = new ArrayList();
              SelectItem si = null;
              try{
                   //-- Connexion
                  Class.forName("com.mysql.jdbc.Driver");
                  conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/databaseName", "root", " ");
                  //-- Creation du statement et de la requete
                  Statement stmt = conn.createStatement();
                  String requete = null;
                  requete = "SELECT ID_,NOM_ FROM materiel";
                  //-- Execution de la requete
                  ResultSet rs = stmt.executeQuery(requete);
                  //-- Lecture des donnees
                  while (rs.next())
                       si = new SelectItem (String.valueOf(rs.getInt(1)), rs.getString(2));
                       items.add(si);
                  //-- Deconnexion
                  conn.close();
              } catch(Exception e){
                  System.out.println("\n\n\nCONNEXION ECHOUEE: "+e+"\n\n\n");
                  System.exit(-1); 
              return items;
    }Here is my Face config :
    <managed-bean>
          <managed-bean-name>genList</managed-bean-name>
          <managed-bean-class>com.demande.action.genList</managed-bean-class>
          <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>Finally here is the error returned :
    Argument Error: An option for component j_id48 was not an instance of javax.faces.model.SelectItem. Type found: java.util.ArrayList.
    (j_id48 is the name given automatically to the combo box)
    I tried a lot of things to repair that error, but nothing works... I can't see where is the problem, if you could help me.
    Thanks,
    Richard T.

    I'm sorry i accidentaly put my topic on the watchlist... I don't know what it is, but I don't know how to correct it ...

  • Combo box error

    I have the following code:
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String sourceURL = "jdbc:odbc:my_Library";
    Connection databaseConnection = DriverManager.getConnection(sourceURL);
    Statement statement = databaseConnection.createStatement();
         ResultSet authorNames = statement.executeQuery("SELECT distinct Topic FROM tblAvailable_Items order by Topic");
         out.println("<select name = \"Topic" + "\">");
         out.println("<option value = \"" + "\"></option>");
                   while(authorNames.next())
                        out.println("<option value=\""+authorNames.getString("Topic")+"\">"+authorNames.getString("Topic"));
         out.println("</select>");
         authorNames.close();
         databaseConnection.close();
    catch(ClassNotFoundException cnfe)
    out.println(cnfe);
    catch(SQLException sqle)
    out.println(sqle);
    For some reason this prints out a combo box with no entries in it, whereas if I remove the value parts it works fine. I need the value bits though, any ideas?

    The getString("") is a static method on ResultSet, that means, you can only call once per each record. Any further calls to getString() on the same column will return a null.
    So, the solution is, store the value in a variable and reuse it.
    while(authorNames.next())
    String topic = authorNames.getString("Topic");
    out.println("<option value=\""+ topic +"\">"+topic);
    -Srinath

  • VBA Userforms – Getting errors when item from combo box is not selected

    Hi there
    Thank you in advance for taking the time to check this out.
    Objective:
    I have 2 combo boxes, one is dependent on what has been selected in the first combo box (dynamic named range), they work fine except for an irritating error when the user accidentally clicks in the empty
    Cmbox_IncCategory and it won’t allow the user to go back to the
    cmbx_Category_Type box if the user forgot he had to make a selection from that first before selecting the
    Cmbox_IncCategory.
    The error that pops up is “Invalid property value”.
    I tried having text in there to say “please select from Cmbox_IncCategory first, but that didn’t fix it.
    I tried to ‘If error resume next’ but that didn’t like it either. Now I am stumped.
    Main combo box= cmbx_Category_Type
    2nd combo box (displaying a list dependent on what was selected in Main combo box)= Cmbox_IncCategory
    I know there must be a way to fix it so that if a user clicks on the combo box, but doesn’t make a selection it won’t lock up the form.
    Yes, it is a mandatory field, and I was considering using a message box to advise the user that this must be completed, but I am not sure how to do it (and avoid the errors
    Here’s the current code I have for the combo boxes.
    Me.Cmbox_IncCategory = "" 'Clears the contents of the 2nd combobox when another category is chosen
    On Error Resume Next
    'I can't seem to have the Incident Category combobox to be empty when the form is open _
    I have tried Cmbox_IncCategory.Value = "", but I get an error. I then tried Cmbox_IncCategory.text = "" _
    but also get the error. I don't know how else to get it to work .. I tried both codes in the _
    form_initialize, but get an error ... I'm stumped !
    Select Case Me.cmbx_Category_Type
    Case "Crime"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_CRIME"
    Case "Property Damage - Minor - NS"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_PROPRTY_NS"
    Case "Property Damage - Significant - S"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_Proprty_S"
    Case "Safety"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_SAFETY"
    Case "Security Breach"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_BREACH_S"
    Case "Support"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_SUPPORT"
    Case "Vehicle"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_VEHICLE_S"
    End Select
    End Sub
    I’d be really grateful if someone could help me out, or perhaps direct me to where I might find some coding that will achieve the result I am seeking.
    This links to
    My Sample form
    With much gratitude,
    TheShyButterfly
    Hope you have a terrific day, theShyButterfly

    Hi Peter,
    Thank you for your quick response :) Brave man! :)
    Both combo boxes are blank to start with (because nothing has been selected). If I click on the first combo box (cmbx_Category_Type) which lists the main events/category types, but I don't select any thing, and I click in the secondary box
    (Cmbox_IncCategory) and then click on any other control, I get an “Invalid property value” error. When I click OK on the error (a few times) and I return to the code window, it gives no indication where/what is breaking
    the code/causing the error. I have no choice but to exit the form by stopping in the code window.
    If I click on the first textbox, (cmbx_Category_Type), and then do the right thing and make a selection, then I have no problems with the secondary textbox (Cmbox_IncCategory).
    As I am not that up on VBA I am trying to follow your instructions... I have changed the code as follows, removed and replaced the rowsource name, but I encounter the very same problem.
    When I changed my code from Me.Cmbox_IncCategory="" to yours myCombo.ListIndex = -1  (changing the combo box name to reflect my combo box name) and adding the second line of code ...
    Me.Cmbox_IncCategory.ListIndex = 0 I still got the same behaviour and error.
    I even tried moving each row of the named rows down one row (so that there would be a 'blank' row which could be selected to get out of trouble, but it wasn't very successful either.
    Have you opened my form to see what happens, I included the link so whoever was looking at my problem (and yes, I have many I know), could see for themselves what it is doing/not doing.
    The code now reads as below (is this what you meant?) - the results were as I mentioned above.
    Me.Cmbox_IncCategory.ListIndex = -1 'Clears the contents of the 2nd combobox when another category is chosen
    Me.Cmbox_IncCategory.ListIndex = 0
    ' On Error Resume Next
    'I can't seem to have the Incident Category combobox to be empty when the form is open _
    I have tried Cmbox_IncCategory.Value = "", but I get an error. I then tried Cmbox_IncCategory.text = "" _
    but also get the error. I don't know how else to get it to work .. I tried both codes in the _
    form_initialize, but get an error ... I'm stumped !
    Select Case Me.cmbx_Category_Type
    Case "Crime"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_CRIME"
    Case "Property Damage - Minor - NS"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_PROPRTY_NS"
    Case "Property Damage - Significant - S"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_Proprty_S"
    Case "Safety"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_SAFETY"
    Case "Security Breach"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_BREACH_S"
    Case "Support"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_SUPPORT"
    Case "Vehicle"
    Me.Cmbox_IncCategory.RowSource = "Inc_Cat_VEHICLE_S"
    End Select
    End Sub
    I appreciate your patience :) I am growing in knowledge, but its a slow process. Please let me know if there is anything else I can help clarify for you :)
    This links to
    My Sample form
    Thanking you again
    TheShyButterfly
    Hope you have a terrific day, theShyButterfly

  • Combo box in "Filter by Custom Properties"

    Hi to all,
    I create some custom metadata properties  properties in order to classifie the documents in KM.
    This metadata properties has a set of Allowed Values, so the value is selectable with a combo-box in Detail box of KM.
    Now I have to enable the Filter by Custom Properties with the combobox in place of textfields.
    How to do?
    Regards,
    Giampaolo

    What you want is not the Filter by Custom Properties but the Filter by Predefined Properties.
    In you search options configuration add your properties to the predefined properties list and you'll get your combo-box.
    To configure your search options go to:
    System Administration -> System Configuration -> Knowledge Management -> Content Management -> User Interface -> Search -> Search Options Set

  • Error reading a combo box in SBO 2004

    Hi
    I am trying to check if someone has selected a value in a combo box on the service call screen (origin field). I can read the value fine if the combo box has a value in it, but if the box is empty I get an error 'object variable or with block variable not set'
    Can anyone suggest anything please ?
    Regards Andy

    Hi John
    Thanks for your idea, I will give that a go
    Regards Andy

  • Report error when using combo box and one text field is empty

    I'm building an interactive pdf in adobe pro 9. My problem is the following: I have one text field where you can enter a numeric code and that is used to populate another text field when I choose an option on one combo box.For example: suppose I write the code 123 in the text field "A" and that the combo box has two options ("data" and "-"). When I select "-", another text field "B" is empty, while when I select "data" i populate the text field "B" using the code entered "A" with the text "data_123". In order to do this I use the standard javascript code in the Format>Custom tab of the combo-box.
    My questions are:
    - how can I prevent the pdf to proceed selecting an option in the combo box when the field "A" is empty?
    - how can I update the field "B" every time that I change the text in "A"? I found that the text is "B" is updated only when I press the selection in the combo box.

    You can set the combo box to read-only in the Validate event of the A field:
    // Validate script for text field
    getField("combo1").readonly = !event.value;
    To update the value of B when A changes, you can expand the script above to something like:
    // Validate script for text field
    var f1 = getField("combo1");
    var f2 = getField("B");
    // If there is an entry in the A field...
    if (event.value) {
        f1.readonly = false;  // Make sure the combo box is activated
        f2.value = f1.value === "-" ? "" : "fa.value + event.value;  // Update the value of field B
    } else {
        f1.readonly = true;  // Deactivate the combo box
        f2.value = f2.defaultValue;  // Reset field B
    You might also want to reset the combo box somewhere in there, but it's not clear to me when you would want to do that.

  • Error with Combo Box, Executing CBTA Script

    Dear Experts.
    I am Using CBTA in solman 7.1 SP 12 to automate the testing with SAP ERP (SAP GUI) and CRM(CRM UI). We are creating the test script without problem, but at time to execute, it suddenly stop.
    We were checking and found that always is failing with a Combo Box field.
    do you know if exist any note to correct this behavior?
    In CRM UI, the script recording create the following component to fill the combo box
    But in the execution CBTA does not fill the field, just try focus in the field, show the values but does not select any.
    At the end show the following error
    IN SAP ERP
    In ERP, the script recording create the following component to fill the combo box
    But in the execution CBTA does not fill the field, just try focusing in the field show the values but does not select any.
    Then the script execution fail  and show  a error, saying the field is read only.
    Br.
    Juan

    Hi every One.
    Finally i got the solution, the error was that i had set up in SAP GUI the option to view the key in the drop down list and the same happened in CRM UI i had set up the same option.
    After shot down this option we record  the escenario again, then we execute it and run without problem.
    Best regards
    Juan

  • Error with combo box

    hi
    my combo  box  returns me a error
    " return without gosub"
    this also happens it I put another combo box in its place
    the error is says  is number 2950
    any help appreciated
    steve

    When that happens, hit Ctrl+Break, so you will break into the debugger. You probably have an inappropriately used "Return" statement. VBA only uses Return in very specific and unusual situations, NOT to return a value from a function.
    Wrong:
    function f() as integer
      return 5
    end function
    Good:
    function f() as integer
      f = 5
    end function
    -Tom. Microsoft Access MVP

  • Error when populating combo box

    I tried to display my data in combo box from my access table but my combo box is empty. Here's my code:
    <% String temp="";     
         Connection conn = null;
         try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              conn = DriverManager.getConnection("jdbc:odbc:admin_management");
              Statement stmt = conn.createStatement();
              ResultSet rs = stmt.executeQuery("SELECT Virtual_host_name FROM Server_Info");
    %>
    <select name="Server_available">
    <%
    while (rs.next()) {
    temp= rs.getString("Virtual_host_name"); %>
    <%System.out.println("<OPTION VALUE=" + temp + ">" + temp + "\n");%>
    <%}%>
    </select>
    <!-- HEADER STARTS HERE--->
    <%
         catch(SQLException e)
              //out.println("SQLException: " + e.getMessage() + "<BR>");
              while((e = e.getNextException()) != null)
              out.println(e.getMessage() + "<BR>");
         catch(ClassNotFoundException e)
              out.println("ClassNotFoundException: " + e.getMessage() + "<BR>");
         finally
              if(conn != null)
         try
              conn.close();
         catch (Exception ignored) {}
    %>
    Please help me asap. thanks!!

    Instead of "System.out.println" try using "out.println"

  • Custom paint for a combo box?

    Is there a document anywhere that describes all the parts you need to paint for a combo box? We have a particular need for a special presentation, but combo boxes can be rather complicated to paint all the parts correctly.
    TIA!

    don't know of a document, but an example of a (color) modified comboBox is here
    [http://forums.sun.com/thread.jspa?forumID=57&threadID=5283094]
    you just have to copy all of the code (it does run)

  • ABAP Webdynpro cannot display value help, combo box properly in IE ?

    Hi WDA expert,
    I have problem developing webdynpro in NW 7.0 EHP1 SPS02. All the combo box, value help, drop down input did not properly display using IE 7.0 / 8.0. It is something like create another  blank input beside the original object.
    but everything ok if i am using mozilla firefox.
    I am not sure what is the problem with this.
    Please help.
    Thank You and Best Regards
    Fernand.

    Hi Thomas,
    Thank you for your response, But i am still not able to solve the problem. Let me give you more detail information regarding this issue.
    are you using the Portal? The other poster in this thread seems to think so, but I don't see anything in your postings to indicate that. IE7 is supported on your release/SP level. IE8 is not supported until SPS5.
    => I am not using portal it is just normal test from SAP GUI. I am using IE 8.0.6001.18702. So far i have tested the sample webdynpro "WDR_TEST_SELECT_OPTIONS" to 4 different server (PID, PIQ, ECD, ECQ) all using the same version NW 7.0 EHP 1 SPS02. (i have check for ABAP and BASIS package). The problem only occur in PID (Initially the icm service is not start so i use transaction SICF to start the webdynpro service) not sure if there is missing java script library ?
    Please refer in this link for the different result screen capture below:
    http://i802.photobucket.com/albums/yy310/pisuper/WDA_DEV.jpg   --> error in PID
    http://i802.photobucket.com/albums/yy310/pisuper/WDA_QA.jpg    -
    > success in PIQ, ECD, ECQ
    I would recommend clearing your browser cache and the server side cache. For the server side cache go to transaction SMICM and choose Administration->ICM->Exit Hard->Global.
    I have restarted the whole server and i did again from SMICM. But still having the same problem like in the screen capture.
    Are you using a standard or customized theme?
    I am using standard theme base on demo "WDR_TEST_SELECT_OPTIONS"
    Base on my latest investigation seems like those 3 success server PIQ, ECD and ECQ always download this file ls_ie6.nosprite.css in the internet temporary directory, but then no for PID. 
    is that any idea or suggestion that i can try to solve this problem. it seems like some configuration was missing for the standard theme in PID
    Thank You and Best Regards
    Fernand Lesmana
    Edited by: Fernand Lesmana on Jun 16, 2010 3:52 PM

  • Grid Combo Box

    I took the code for creating a combo box inside the grid but I have a problem when I change the label of the column that attached to the combo box. It gave me error about identifier not found.
    The setDataItemName method I didn't touch it.
    any idea ,.. appreciated.
    DT
    public class myGridComboBox1 extends ComboBoxControl {
    public myGridComboBox1(ScrollableRowsetAccess m_Rs, JTable m_Table, String
    grid_columnName, String combo_columnName ) {
    int rowCount = m_Rs.getRowCount();
    Object comboData[] = new Object[rowCount];
    try{
    for (int iRow=0; iRow<rowCount; iRow++){
    m_Rs.absolute(iRow+1);
    ImmediateAccess ia =
    (ImmediateAccess)m_Rs.getColumnItem(combo_columnName);
    String str = ia.getValueAsString();
    comboData[iRow] = str;
    }catch(Exception e){
    e.printStackTrace();
    // get reference to a column
    TableColumn customColumn = m_Table.getColumn(grid_columnName);
    // custom TableCellRenderer
    TableCellRenderer myTCR = new ListCellRenderer(comboData, rowCount);
    // forces this column to use the custom Cell Renderer
    customColumn.setCellRenderer(myTCR);
    TableCellEditor myTCE = new DefaultCellEditor(new JComboBox(comboData));
    customColumn.setCellEditor(myTCE);
    // inner class for custom CellRenderer (ComboBox)
    class ListCellRenderer extends ComboBoxControl implements
    TableCellRenderer{
    public ListCellRenderer(Object cData[], int iRow)
    super();
    for (int i=0; i<iRow; i++)
    addItem(cData.toString());
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected,
    boolean hasFocus, int row, int column)
    setBackground(isSelected && hasFocus ? table.getSelectionBackground() :
    table.getBackground());
    setForeground(isSelected && hasFocus ? table.getSelectionForeground() :
    table.getForeground());
    setFont(table.getFont());
    setSelectedItem(value);
    return this;
    null

    You should pass the name of the attribute,
    not the label to the "MyGridComboBox"
    constructor.(As grid_ColumnName).
    Hope helps.

  • Adding an event listener to combo box

    I am working on a mortgage calculator and I cannot figure out how to add an event listener to a combo box.
    I want to get the mortgage term and interest rate to calucate the mortgage using the combo cox. Here is my program.
    Modify the mortgage program to allow the user to input the amount of a mortgage
    and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.50%, and
    30 year at 5.75%. Use an array for the different loans. Display the mortgage payment
    amount. Then, list the loan balance and interest paid for each payment over the term
    of the loan. Allow the user to loop back and enter a new amount and make a new
    selection, with resulting new values. Allow user to exit if running as an application
    (can't do that for an applet though).
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    //creates class MortgageCalculator
    public class MortgageCalculator extends JFrame implements ActionListener {
    //creates title for calculator
         JPanel row = new JPanel();
         JLabel mortgageCalculator = new JLabel("MORTGAGE CALCULATOR", JLabel.CENTER);
    //creates labels and text fields for amount entered          
         JPanel firstRow = new JPanel(new GridLayout(3,1,1,1));
         JLabel mortgageLabel = new JLabel("Mortgage Payment $", JLabel.LEFT);
         JTextField mortgageAmount = new JTextField(10);
         JPanel secondRow = new JPanel();
         JLabel termLabel = new JLabel("Mortgage Term/Interest Rate", JLabel.LEFT);
         String[] term = {"7", "15", "30"};
         JComboBox mortgageTerm = new JComboBox(term);
         JPanel thirdRow = new JPanel();
         JLabel interestLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
         String[] interest = {"5.35", "5.50", "5.75"};
         JComboBox interestRate = new JComboBox(interest);
         JPanel fourthRow = new JPanel(new GridLayout(3, 2, 10, 10));
         JLabel paymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
         JTextField monthlyPayment = new JTextField(10);
    //create buttons to calculate payment and clear fields
         JPanel fifthRow = new JPanel(new GridLayout(3, 2, 1, 1));
         JButton calculateButton = new JButton("CALCULATE PAYMENT");
         JButton clearButton = new JButton("CLEAR");
         JButton exitButton = new JButton("EXIT");
    //Display area
         JPanel sixthRow = new JPanel(new GridLayout(2, 2, 10, 10));
         JLabel displayArea = new JLabel(" ", JLabel.LEFT);
         JTextArea textarea = new JTextArea(" ", 8, 50);
    public MortgageCalculator() {
         super("Mortgage Calculator");                     //title of frame
         setSize(550, 350);                                             //size of frame
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container pane = getContentPane();
         GridLayout grid = new GridLayout(7, 3, 10, 10);
         pane.setLayout(grid);
         pane.add(row);
         pane.add(mortgageCalculator);
         pane.add(firstRow);
         pane.add(mortgageLabel);
         pane.add(mortgageAmount);
         pane.add(secondRow);
         pane.add(termLabel);
         pane.add(mortgageTerm);
         pane.add(thirdRow);
         pane.add(interestLabel);
         pane.add(interestRate);
         pane.add(fourthRow);
         pane.add(paymentLabel);
         pane.add(monthlyPayment);
         monthlyPayment.setEnabled(false);
         pane.add(fifthRow);
         pane.add(calculateButton);
         pane.add(clearButton);
         pane.add(exitButton);
         pane.add(sixthRow);
         pane.add(textarea); //adds texaarea to frame
         pane.add(displayArea);
         setContentPane(pane);
         setVisible(true);
         //Adds Listener to buttons
         calculateButton.addActionListener(this);
         clearButton.addActionListener(this);
         exitButton.addActionListener(this);
         mortgageTerm.addActionListener(this);
         interestRate.addActionListener(this);
    public void actionPerformed(ActionEvent event) { 
         Object command = event.getSource();
         JComboBox mortgageTerm = (JComboBox)event.getSource();
         String termYear = (String)mortgageTerm.getSelectedItem();
    if (command == calculateButton) //calculates mortgage payment
         int year = Integer.parseInt(mortgageTerm.getText());
         double rate = new Double(interestRate.getText()).doubleValue();
         double mortgage = new Double(mortgageAmount.getText()).doubleValue();
         double interest = rate /100.0 / 12.0;
         double monthly = mortgage *(interest/(1-Math.pow(interest+1,-12.0 * year)));
                   NumberFormat myCurrencyFormatter;
                   myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
                   monthlyPayment.setText(myCurrencyFormatter.format(monthly));
         if(command == clearButton) //clears all text fields
                   mortgageAmount.setText(null);
                   //mortgageTerm.setText(null);
                   //interestRate.setText(null);
                   monthlyPayment.setText(null);
              if(command == exitButton) //sets exit button
                        System.exit(0);
         public static void main(String[] arguments) {
              MortgageCalculator mor = new MortgageCalculator();

    The OP already did this to both JComboBoxes.
    mochatay, here is a new actionPerformed method for you to use.
    I've improved a few things here and there...
    1) You can't just cast the ActionEvent's source into a JComboBox!
    What if it was a JButton that fired the event? Then you would get ClassCastExceptions (I'm sure you did)
    So check for all options, what the source of the ActionEvent actually was...
    2) You can't assume the user will always type in valid data.
    So enclose the Integer and Double parse methods in try-catch brakcets.
    Then you can do something when you know that the user has entered invalid input
    (like tell him/her what a clumsy idiot they are !)
    3) As soon as user presses an item in any JComboBox, just re-calculate.
    I did this here by programmatically clicking the 'Calculate' button.
    Alternatively, you could have a 'calculate' method, which does everything inside the
    if(command==calculateButton) if-block.
    This will be called when:
    a)calculateButton is pressed
    b)when either of the JComboBoxes are pressed.
    public void actionPerformed (ActionEvent event)
            Object command = event.getSource ();
            if (command == calculateButton) //calculates mortgage payment
                int year = 0;
                double rate = 0;
                double mortgage = 0;
                double interest = 0;
                /* If user has input invalid data, tell him so
                and return (Exit from this method back to where we were before */
                try
                    year = Integer.parseInt (mortgageTerm.getSelectedItem ().toString ());
                    rate = new Double (interestRate.getSelectedItem ().toString ()).doubleValue ();
                    mortgage = new Double (mortgageAmount.getText ()).doubleValue ();
                    interest = rate / 100.0 / 12.0;
                catch (NumberFormatException nfe)
                    /* Display a message Dialogue box with a message */
                    JOptionPane.showMessageDialog (this, "Error! Invalid input!");
                    return;
                double monthly = mortgage * (interest / (1 - Math.pow (interest + 1, -12.0 * year)));
                NumberFormat myCurrencyFormatter;
                myCurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
                monthlyPayment.setText (myCurrencyFormatter.format (monthly));
            else if (command == clearButton) //clears all text fields
                /* Better than setting it to null (I think) */
                mortgageAmount.setText ("");
                //mortgageTerm.setText(null);
                //interestRate.setText(null);
                monthlyPayment.setText ("");
            else if (command == exitButton) //sets exit button
                System.exit (0);
            else if (command == mortgageTerm)
                /* Programmatically 'clicks' the button,
                As is user had clicked it */
                calculateButton.doClick ();
            else if (command == interestRate)
                calculateButton.doClick ();
            //JComboBox mortgageTerm = (JComboBox) event.getSource ();
            //String termYear = (String) mortgageTerm.getSelectedItem ();
        }Hope this solves your problems.
    I also hope you'll be able to learn from what I've indicated, so you can use similar things yourself
    in future!
    Regards,
    lutha

Maybe you are looking for

  • JMS Queue monitor

    Hi Experts, We have a requirement in PO 7.31 system to monitor the message traffic for sender and receiver jms queues defined in communication channel configurations. These jms queues are managed externally by EAI team. Please let us know how to do t

  • HT4796 attempting to transfer from pc to mac. keeps looking for sources. whats the story with that?

    my pc cannot find my mac. keeps searching

  • How to download and upload BDC programs

    How to download and upload BDC programs from one instance to another instance? I would like to transport my BDC programs from one dev client to another Dev client not through transport like smartforms.(we can download smartforms to desktop and upload

  • Slow and problems opening programs

    Just installed Lion 3 days ago and its loads and runs very slow.  Don't understand why. Secondly when i go to Safari it will not go to the home page when I open, it goes to the last page I was in when i was browsing.  Same with with Excel, word, etc.

  • Problem deleting Master Data from an InfoObject

    Hello Everyone, We have 0MATERIAL infoobject. There was no Master data in the infoobject. Then, i manually entered the data into the InfoObject. After a day, i tried to delete the Master data to load it from R/3. When i tried to delete the Master dat