Can I convert a string to a JComponent

If I have a JButton named "exitButton" and I have a String with the text value = "exitButton" is there any way to convert this string into an object that I can then use to perform actions with, for example:
exitButton.isEnable(false);

Hi, if you have only a feew buttons/components and there know at compiletime. you can make a vectro containing a keypair containign the string and the button if you don't want to do it this way i believe you can do it using the reflection package it can do taht (i believe) never used it myslef but have a look at the reflection api.
Hope This Helps You,
Robert

Similar Messages

  • How can I convert a string to a seperated characters?

    How can I convert a string to a separated characters without using array?
    such as: input = String "word"
    output =
    w
    o
    r
    d
    Thanks

    A string is stored internally in individual characters.
    The String class has a method 'charAt(int index)' which returns the character at that index so using a for loop..
    String s = "word";
    for(int counter=0; counter < s.length(); counter++)
    System.out.println(s.charAt(counter));
    HTH

  • How can I convert a String into an int?

    I need to use command-line args. So I enter "java Main 123" and I want to use 123 not as a String but as an int.
    How can I convert it into an int?
    Thank You!!
    Sprocket

    Example method (you don't need to use a method unless you do this a lot)
    private int stringTOInt (String aString)
    int result = 0;
    try
    result = Integer.parseString(aString);
    catch (Exception ex)
    System.out.println ("Failed to convert string " + aString + " to int.");
    return result;
    }

  • How can I convert a string of hex values to a hex format string programatically?

    Is there a way to convert a string of the following format:
    1400010107070D0305006A01 ........           ("Normal display" string)
    programatically to:
    1400 0101 0707 0D03 05006A01 ..........      ("Hex display" striing)
    I need to do this in order to calculate a CRC16 value.
    See attached VIs
    Thank you.
    Solved!
    Go to Solution.
    Attachments:
    CMM_SN_MULTI.vi ‏50 KB
    CMM_CRC16_Calculator.vi ‏23 KB

    You can iterate over the string and use the String to Hex VI. If you work with two bytes of the string at a time you can get a U8 array of the desired binary values. Then when you are complete you can either work with the byte array of convert it back to a string using Byte Array to String.
    EDIT: GerdW typed faster than I did.
    Message Edited by Mark Yedinak on 03-18-2010 02:55 PM
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How can I convert a string into an image

    I want to convert a string into an image.
    I want to know required steps for that.

    look at http://forum.java.sun.com/thread.jsp?forum=31&thread=194763
    drawString looks as something you might need

  • How can I convert a string to an object or class

    I would like to read a file representing a class, and convert it to an object or a class (object preferred). Other postings suggest using javax.tools.JavaCompiler to convert from a string but then say that this is not always available (posting on 1 Jan 09). If this is still not universally available is there another way to do this? If this is not available, are there any examples of how it should be done?
    My understanding from what I've read is to read the file into a String then compile the String using javax.tools.JavaCompiler, which is an Interface.
    thanks

    skidmarks wrote:
    What i would like to do is to take a Java file representing a class and compile it at runtime. However, the comment about a JDK being available at runtime makes this unattractive.So, you want to compile .java files, but you don't want to have to use a compiler?
    The next guess would to be to create a .jar file and reference it at runtime. Here's the scenario:Eh? How is that even remotely equivalent?
    1. People using the 'system' will have a varied knowledge of Java.
    2. My hope was to require that anyone using the program would only need to create a Java Class file,You mean a Java source file. You have said that YOU want to create the .class file. If they are creating the .class file, then all you need to do is load it with a ClassLoader and start using it.
    You might try clarifying your requirements a bit.
    In either case, the Class Files would look like:
    public class Name {
    int field1;
    float field2;
    } With all the field types being simple Java Primitives.What is the point of this? What are you ultimately trying to accomplish, that can be served by user-defined groups of primitives, with no complex object graphs and no user-defined methods?
    Depending on what you're really getting at, using scripting features via beanshell, groovy, or javascript might be an approach to consider, or using Scala to produce a domain-specific language (although I suspect that last may be overkill, and beyond your current skill level).
    If this is so, is there any way to create a .jar file at runtime? Do I have to exec("jar") or is there another way.A .jar file is just a .zip file with a manifest. Look at the java.util.jar package. But note that creating a .jar file has nothing to do with the rest of what you're asking about.

  • How can I convert a String into boolean?

    I am facing difficulty in converting String into boolean.
    For example, I have a few variable which i need user to input yes or no as the answer. But I uses string instead. Is there a way which i can ask them to input boolean directly?
    Please advise...
    credit = JOptionPane.showInputDialog("Enter Yes or No for Credit Satisfactory : ");
    System.out.println("The answer for Credit Satisfactory : "+credit);
    e_invtry=JOptionPane.showInputDialog("Enter Yes or No for inventry level");
    System.out.println("The answer for Quantity Order : "+e_invtry);
    Message was edited by:
    SummerCool

    Thanks...but I don't get it....I tried to use your
    suggestion but i got the message that " cannot find
    symbol method
    showConfirmDialog(java.lang.String,int)" ???
    Please advise.
    The code I use was :
    int credit = JOptionPane.showConfirmDialog("Enter Yes
    or No for credit satisfactory",
    JOptionPane.YES_NO_OPTION);Well that was not the example I gave you.
    JOptionPane has no method showConfirmDialog that receives a String and an int (exactly what the error message is telling you).
    What was wrong with the version I showed you?

  • Can't convert my String to numbers

    Hi!
    I'm trying to convert my received data to numbers in actionscript in Flex.
    I want to use the numbers that I get in a calculation.
    The function where the data ("Svar") in received and saved in a string looks like this:
    Svar.htmlText = event.result.toString();
    And this is the calculation that I want to do:
    var r:Number = Number(Svar)/2.1;
    var newheight:Number = 420 * r;
    var newwidth:Number = 162 * r;
    resizeLarge.widthTo = newwidth;
    resizeLarge.heightTo = newheight;
    resizeLarge.duration=750;
    I've checked the calculation and it works so it must be something wrong with the
    "Svar" data.
    I'd be really grateful if someone could help me!

    Hi,
    You are doing something wrong with the calculation in the below line of code.
    var r:Number = Number(Svar)/2.1;
    Here what does Svar corresponds to....Is it a variable or a Labeel control....?
    I think Svar is some kind of a Label or Text control since in your code you have used "htmlText: attribute with the "Svar" as shown below.
    Svar.htmlText = event.result.toString();
    So in your calculation also you need to use the same ...I mean ...text property as shown below..
    var r:Number = Number(Svar.text)/2.1;
    Dont use Svar.htmlText  in calculation as it may give include unnecessary htmltags and your conversion from string to Number fails.
    Hope now the things are clear...If you still have any dobt let me know.
    If this post answers your question or helps, please kindly mark it as such.
    Thanks,
    Bhasker Chari

  • How can i convert a string to use on a image property?

    public function excluir(nome:Image):void
                                            nome.enabled = false;
    it's simple...
    I'm trying to use a string who comes from the db to set on image property.
    it's like -> id.enabled = false

    Hi,
    What are you trying to do?
    s:Image is a component in flex, with source property you set the path and name of the image for the s:Image component.
    http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7f9d.ht ml
    If you have a list of images path in the database you can probably read all in arrayCollection and add those images in a list like:
    http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_2.html
    I hope this help

  • How can I convert a String to a DOM document?

    I want to convert the text of a TextArea to a DOM Document - how can I do this?
    Thanks a million,
    Daniel.

    something.parse(new StringReader(theTextArea.getText()));

  • How can I convert string to the record store with multiple records in it?

    Hi Everyone,
    How can I convert the string to the record store, with multiple records? I mean I have a string like as below:
    "SecA: [Y,Y,Y,N][good,good,bad,bad] SecB: [Y,Y,N][good,good,cant say] SecC: [Y,N][true,false]"
    now I want to create a record store with three records in it for each i.e. SecA, SecB, SecC. So that I can retrieve them easily using enumerateRecord.
    Please guide me and give me some links or suggestions to achieve the above thing.
    Best Regards

    Hi,
    I'd not use multiple records for this case. Managing more records needs more and redundant effort.
    Just use single record. Create ByteArrayOutputStream->DataOutputStream and put multiple strings via writeUTF() (plus any other data like number of records at the beginning...), then save the byte array to the record...
    It's easier, it's faster (runtime), it's better manageable...
    Rada

  • How can I convert a space from ABAP to CSV data?

    Hello guys,
    how can I convert a string like
    "This is a%test%"
    to
    "This is  a test "
    into CSV data?
    I try to with   REPLACE ALL OCCURRENCES OF '%' IN string_above WITH space,
    but I got the string without space, like
    "This is  atest"
    I read some posts that CSV will ignore space.
    But which kind of symbol in CSV represents space?
    Thanks for any suggestion!
    Regards,
    Liying

    USE THE CODE AS SHOWN BELOW...
    TYPES : BEGIN OF tp_data,
              line(4096),
            END   OF tp_data.
    *&      Form  gui_upload
          Upload the data from the input file to the internal table
    FORM gui_upload.
    *--Local data declaration
      DATA: l_filename_ip TYPE string,
            tl_data       TYPE STANDARD TABLE OF tp_data WITH HEADER LINE.
      l_filename_ip = p_input.
    *--Upload Data
      CALL FUNCTION 'GUI_UPLOAD'
           EXPORTING
                filename                = l_filename_ip
                filetype                = 'ASC'
                has_field_separator     = ''
           TABLES
                data_tab                = tl_data
           EXCEPTIONS
                file_open_error         = 1
                file_read_error         = 2
                no_batch                = 3
                gui_refuse_filetransfer = 4
                invalid_type            = 5
                no_authority            = 6
                unknown_error           = 7
                bad_data_format         = 8
                header_not_allowed      = 9
                separator_not_allowed   = 10
                header_too_long         = 11
                unknown_dp_error        = 12
                access_denied           = 13
                dp_out_of_memory        = 14
                disk_full               = 15
                dp_timeout              = 16
                OTHERS                  = 17.
      IF sy-subrc <> 0.
        MESSAGE ID   sy-msgid TYPE 'S' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        IF sy-subrc = 1.
          MESSAGE e000 WITH text-e04.
        ENDIF.
      ELSE.
        LOOP AT tl_data FROM 2.
    *--Taking the contents of the input file leaving the header part
          PERFORM split_and_save USING tl_data-line.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " gui_upload
    *&      Form  split_and_save
          Splitting the contents from the input file and saving them into
          an internal table
         -->P_TL_DATA_LINE  text
    FORM split_and_save USING fp_data.
    *--Local data declaration
      DATA : tl_data TYPE STANDARD TABLE OF tp_data WITH HEADER LINE,
             l_type  TYPE c,
             c_space(1) TYPE c VALUE ' '.
    *--Split at the Comma
      SPLIT fp_data AT c_space INTO TABLE tl_data.
      CLEAR inputtab.
    *--Move it to the target fields
      DO.
        ASSIGN COMPONENT sy-index OF STRUCTURE inputtab TO <fs_field>.
        IF NOT sy-subrc IS INITIAL.
          EXIT.
        ENDIF.
    *--Extract source data
        CLEAR tl_data.
        READ TABLE tl_data INDEX sy-index.
    *--Populate the target
        <fs_field> = tl_data-line.
      ENDDO.
    *--Append this record
      APPEND inputtab.
    ENDFORM.                    " split_and_save
    In the above code u can use make inputtab like tp_data and get the result as requires in an internal table as space seperated fields.
    In place of space u can also use any other symbol.
    And after that u can replace all occurences of space with the comma by using the statement that u have written below.

  • Convert from String to HashMap

    Hi
    Can any body pls tell us how to convert from String to HashMap
    I have one string str="Col1=200, Col2=225";
    So how can i convert that string varibale into HashMap?

    Hi
    Can any body pls tell us how to convert from String
    to HashMap
    I have one string str="Col1=200, Col2=225";
    So how can i convert that string varibale into
    HashMap?
    Map map = new HashMap();
    String[] parts = str.split(", ");
    for (int i = 0; i < parts.length; ++i) {
        String[] entry = parts.split("=");
    map.put(entry[0], entry[1]);

  • How to convert a string into an objects name?

    Hi
    I have the following problem;
    I have a string
    String a = "e1"
    and a method
    call(Event e1) that calls the "Event" class with object the name of the string a.
    How can I convert the strings name into an object so as to use it in the "call" method?
    Any ideas?
    Thanks in advance

    I don't know if this helps you, but you can do things like this.
    String a = "com.example.SomeEvent";
    //Instantiate com.example.SomeEvent
    Object o = Class.forName(a).newInstance();SomeEvent must have a non-argument constructor for this to work.
    Class that will be instantiated depens on runtime value of String a, and can be different across different executions of the program.

  • Converting a String to Date

    I have a String in which i am storing the date which I have retrieved from database. How can I convert this String to a Date object and use Comparator for sorting.
    String strCreatedDate1 = ((CVendorEmployees) vendoremployee1).getCreatedDate().toUpperCase();The date format which I will retrieve from String is mm/dd/yyyy.
    I want to convert this into date and use it for sorting.
    Thanx.

    Date dtTmp = new
    SimpleDateFormat("dd-MM-yyyy").parse(((CVendorEmployee
    s) vendoremployee1).getCreatedDate());
                                  Calendar calendar = Calendar.getInstance();      
                                  calendar.setTime(dtTmp);
    Now you have the date object do what ever you wish toBetter make thatnew SimpleDateFormat("MM/dd/yyyy")And no need for the Calendar stuff if all you want is a Date object.

Maybe you are looking for

  • To be able to report by business area at a header level

    Business area reporting at a header level in Procurement/AP Subject Areas At present client is doing a large number of manual lookups in Excel to add Business area detail to certain OBI procurement reports. Reasons for why we are having to do this in

  • How can I find a pdf in a Ipad when previously was uploades from Mac  onto Icloud Drive?

    AFter uploaded my pdf from my Mac onto Icloud Drive,  I go to my Ipad, open PDF App look in document and I do not find my document that was previously uploaded. can any one help me?

  • Max time between log

    Hello, In LabVIEW DSC 7.1 there was the parameter "maximum time between logs" setting in Configure>>Historical menu. This parameter has been removed in LabVIEW DSC 8.2. Is there anything I have to do to force the same "maximum time between logs" beha

  • Error Cancelling Release of Basic Type

    Hi, Im using WE30 to make changes to a BASIC type. So in the menu EDIT->Cancel Release an error prompted these messages: The release of the basis types cannot be reset Message no. EA506 Diagnosis The release can only be reset if the basis type has be

  • Canon iP4200 - an error occured while trying to add the printer Error -9672

    It seems I am one of the hoard of folks unable to add my printer (in my case, a canon iP4200) to the Airport Extreme network. I have repaired permissions I have reinstalled the lastest driver I have read through the discussions The airport was sold i