Button Name

Button newbutton = new Button(string); Java automatically assignes a name to each of these buttons that are created in my app. (button0 - button16) There is a way to get their names but I forget. I tried getName() but that just returns the name of the frame that they are in. What is the correct statement to use?
full code:
class ButtonPanel extends TopPanel
          public ButtonPanel(String A)
               int strA = Integer.parseInt(A);
               int globalclasssize = strA;
               int gridSize = (int)( Math.ceil( Math.sqrt(globalclasssize) ));  //this line takes the sqrt of the number
               this.setLayout(new GridLayout(gridSize,gridSize));            // entered and rounds up to make a suitable grid.
               int idnum = 1;
               for(int num = 0; num<globalclasssize;num++)
                    int id = idnum++;
                    this.add( getButton("Desk " + id) );
                    this.add( getSpacer("") );
               this.setVisible(true);
          public Button getButton(String string)
               Button newbutton = new Button(string);
               newbutton.addActionListener(new java.awt.event.ActionListener()
                                   public void actionPerformed(java.awt.event.ActionEvent bevt)
                                             enterbActionPerformed();
               seatname = getName();
               System.out.println(seatname);
               return newbutton;
          public Button getSpacer(String string)
               Button newbutton2 = new Button(string);
               newbutton2.setVisible(false);
                 return newbutton2;
/* Action Events for Button */
public void enterbActionPerformed()
    seatname = getWHATGOESHERE();
    System.out.println(seatname);
}

The information you need to identify the button that generated the action event is in the event object bevt. If you're going to use another method for the actionPerformed() method body you must send along the event object:
public void actionPerformed(ActionEvent e) {
  enterbActionPerformed(e);Here's a way to get the button id in actionPerformed:
public void actionPerformed(ActionEvent e) {
  Button button = (Button)e.getSource();
  String ac = button.getActionCommand();
  // if you had declared the button names, eg, Button Desk1, Desk2,...;
  // then you could use
  if(button == Desk1) {
    // what to do when Desk1 is pressed
  // another way is to use the action command
  // there is a caveat with this approach: if your code gets translated
  // into another language the text on the buttons will change which
  // will change the action commands, unless you set them explicitly
  // (this is a bit tricky the way you wrote your code)
  if(ac.equals("Desk1")) {
    // carry on
  // to set the action command
  newbutton.setActionCommand(string);
  // in getButton()

Similar Messages

  • Change Button Name in JOptionPane.showMessageDialog

    Hello,
    I've written the following code that invokes a JOPtionPane messageDialog, when the delete button is hit in the following frame and the selectedItem in the JComboBox is Default.
    I want to change the JOPtionPane button name from OK to Close. Is there a way to do this with error message dialoges, as their is with confirmDialoges?
    Please help out.
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class MyJOptionPaneTest {
         public MyJOptionPaneTest()
              JFrame frame = new JFrame("My Frame");
              JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT,5,0));
              final JComboBox myComboBox = new JComboBox();
              myComboBox.setPreferredSize(new Dimension(100,20));
              myComboBox.getModel().setSelectedItem("Default");
              myComboBox.addItem("Default");
              myComboBox.addItem("Other");
              JButton deleteButton = new JButton("Delete");
              deleteButton.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        if(myComboBox.getSelectedItem().equals("Default"))
                             JOptionPane.showMessageDialog(null, "Default cannot be deleted", "Error", JOptionPane.ERROR_MESSAGE);
              panel.add(myComboBox);
              panel.add(deleteButton);
              frame.getContentPane().add(panel);
              frame.setSize(200,100);
              frame.setResizable(false);
              frame.setVisible(true);
         public static void main(String [] args)
              MyJOptionPaneTest test = new MyJOptionPaneTest();
    }

    Hi,
    yes, I've looked at the tutorials. But there is no way to change button title for JOptionPane.showMessageDialog. Only JOptionPane.showOptionsDialog provides you w/ that feature, becuz it provides the parameter in the method.
    I was wondering if there was another way to do this for showMessageDialog.

  • Change button name in a for-loop

    Hi all,
    I would like to implement a 'for loop' to add buttons to my panel depending on the value of max_number.
    The postion of these buttons will also change with each passing of the loop.
    The code below implements this. But when I click the buttons they only return the action listener of the last button drawn. This is because the JButton my_button is reused in each pass through the loop.
    What I need is to change the name of the button on each passing of the loop so that I create a new button each time with it's own unique action listener.
    Is there a way of adding/appending the value of 'i' to the button name each time the for loop is run?
    For example
    When i = 0 -> JButton my_button0 = ...
    When i = 1 -> JButton my_button1 = ...
    etc, etc,
    for (i = 0; i < max_number; i++)
    JButton my_button = new JButton(Integer.toString(i));
    my_button.addActionListener( new ActionListener()
    { public void actionPerformed(ActionEvent event)
    { do something depending on the value of 'i' }});
    addComponent(my_button, (2*i+1) , 4 , 1 , 1); //add newly created button to position x = (2*i+1), y = 4
    } //end for

    What?! Are you talking about the variable name? You can't, shouldn't, needn't use different variable names in a for loop, since the variables "expire" each time the loop is run. For instance:
    for(int i = 0; i < 10; i++) {
       //j doesn't exists even if this loop is on its 10'th lap!
       int j = i;
    }And you will have a problem with the ActionListener as well, since it depends on the "i" variable. "i" can't be accessed from an anonymous class unless it has been declared final, in which case it won't work for you.
    So: the my_button variable will contain a new JButton each time!
    Nille

  • Exporting each articles button names to an Excel Spread Sheet or other form

    Is there a way to export a list of all the button names in each article to an Excel spread sheet or some other form? If someone knows of a script that does this that would work to. The button names are based on their function: OL = Overlay, TAB = Tab and BTN = Button. Here is an example of one of the articles that we have gone through and named the buttons and what they do. We just do not want to have to go to each button in each article and copy and past it to an Excel doc.

    @stephen0218 – with the following line or the ones that you are using:
    app.documents[0].buttons.everyItem()
    you will hardly address all buttons in a document.
    At least not in a document that is prepared for ADPS.
    You'll get just the ones that sit plain on the page: not inside groups, not inside other objects like rectangles or states of MultiStateObjects (MSOs).
    You will have more luck if you are using "allPageItems" and sorting out the buttons.
    But be aware that "allPageItems" is blind to objects (also buttons) in states of MSOs that do not belong to the active state.
    Uwe

  • How to get the button name which triggred the post back

    i have multiple buttons on the apex page most of those have the event type as "post back". is there any way to get the button name through pl/sql which raised the post back event ?

    Tried v('REQUEST') or :REQUEST?

  • Change button names

    Hi Experts,
    Is it possible to change the button name in SAP documents? Ex. SO button 'ADD' changed to 'SAVE'.
    Thanks.
    Don

    Hi Don,
    Unfortunately, it is not possible to change button names, we can only change label names. If you want to change button names, you need to customize an addon.
    Hope it helps.
    Chinho

  • Run time update on Button name and Action of Button

    I want to change the button name and button path in the GUI directly. So user can update GUI as per their requirement.
    Now I have built a GUI with multiple buttons. Whenever the button clicked corresponding webpage will be opened. This Button name and webpage link can not be changed as per current GUI design.
    But I want to allow anybody to update the Button name and webpage link as per their need.
    Please suggest , how can I achieve it? Please share if you have some code snippet.

    Changing the text on a Swing JButton is pretty simple. That isn't an appropriate question for this forum, however. This forum is for questions concerning using or extending WindowBuilder. General Swing questions should be posted to a general Swing/Java forum.

  • Set variable equial to button name that was clicked

    I know how to do this in Flash, but don't see a way to do it in captivate? When one of 26 buttons are clicked, I need to set a varaiable with the button name. Then jump to a page that has 26 grahics hiden. On enter I need to unhide the one named the same as the button.

    I'm glad I saw this post at the top of the list.  I wanted to do this too.  I have 15 click boxes that are used as bonus points.  When clicked I would like to do the following:  (1) Hide the click box and icon group that was clicked.  (2) Increase my "score" variable.
    It would be nice if it used the "this" function, like is done in Jquery / javascript, along with wildcards in the variable name.  This way, I could create 1 Advanced Action script that could work for any of the click boxes.
    Oh well...I'm off to creating 15 scripts.  Maybe I'll watch a movie while I do it. 
    Micky

  • Changing Prompt Button Name "Go" to "Apply"

    Hi,
    I want to change the prompt button name from "Go" to "Apply".
    How to achieve this?
    Thanks,
    Satheesh

    Hi, you can refer to http://bischool.wordpress.com/2009/07/18/change-go-button-name-of-obiee-dashboard-prompt/
    or
    http://www.obinotes.com/2010/09/change-go-button-text-in-prompt-only.html
    I hope this helps.
    J.-

  • How to extract button name after message popup step completed?

    Hello!
    I wonder is it possible to get the pressed button name from "message popup"? It is easy to get button index, but I don't find a way to get buttons array. Is it possible to get buttonNlabel substituting N from button hit?
    Thank you in advance!

    Sure, just build an expression to do it. For example from the following step you could use:
    Evaluate(Evaluate("RunState.PreviousStep.Button" + str(RunState.PreviousStep.Result.ButtonHit) + "Label"))
    The inner Evaluate returns the expression for the button label, which is usually a string constant. The outer Evaluate evaluates that expression, which in the case of a string constant just removes the quotes.

  • Button name variable?

    Hi,
    I am trying to create a small piece of javascript code that is called when I press a button on a page. At the end of the javascript the regular doSubmit is called.
    The javascript looks something like this
      function mySubmit(pRequest){
        /* my javascript here */
        doSubmit(pRequest);
      }The button calls the function like this:
      javascript:mySubmit('APPLY');However, I'd like to make it as generic as possible. Now I have to insert the correct name of the button into the call, so that it is passed on to doSubmit.
    Is it possible to substitute the actual button name with a variable:
      javascript:mySubmit('#BUTTON_NAME#');Or is there another trick that does not require the button name(=request) to be specified explicitly?
    Thanks!
    Rob

    Hi ATD,
    Thanks very much for your reply.
    I'm having some problems with the javascript though :(
    The function is called with this as a parameter :
    &lt;a href="javascript:html_Submit_Progress(this);"&gt;
      &lt;img src="/i/ph_btn_apply.gif" alt="Apply" border="0"  /&gt;
    &lt;/a&gt;This is the function
    function html_Submit_Progress(pNode){
      var i = pNode.getElementsByTagName('IMG');
    }And the function gives an error on the very first line.
    Firefox says: pNode.getElementsByTagName is not a function
    IE: Object doesn't support this property or method.
    I know this is not a javascript forum... but if there's anyone who can help me with this, I'd be very thankful.

  • Radio button 'Names' and grouping

    Ok, I am still working on my Monster form...
    Probably pushing the envelope for what Forms can do...but hey...
    My "buttons" are all named "Button.section.number"  (ex. Button.1.13) so that my validate scripts can quickly go through and build other tables and things....
    In each section, there are 3-4 buttons where I want at-least-one to be selected.
    Obviously, a "Radio Button" will give me ONLY one selected, but I am having NAME problems in that when I try to name them so the scripts will work the button  come out of the group. (and crash Acrobat)
    so...in a section, what I want to have is:
    Button.2.0     (.hidden,  .value = "Grounds")
    Button.2.1 \
    Button.2.2  want these 4 in an exclusive group, where an entry is ".required" for at least one of them
    Button.2.3 /
    Button.2.4              A validate script runs later that looks for "blank" .required fields and reports out using "userName" in an "appAlert"
    Button.2.5
    Button.2.16  (.hidden, .value= "MAX")
    My Validate scripts go through all the sections and all the buttons finding boxes that are checked that represent problems, and copy's the fields "Export Data" to a summary page -AND- looks for empty .required fields  (and other things)
    I would LIKE the user to be forced to select  one of : Serviceable, Deficient, Hazard or N/A  for each section.  (Button.1.1, Button.1.2, Button.1.3, Button.1.4 in this example)
    Do I need a "button_up" script (the same in all 4 buttons) that makes sure there is at least one selected. and clearing/setting the .required's on the fields ?  That seems messy.  I could start the form with the last choice (N/A) checked, but that seems error prone. 
    The current validate script checks for empty .required fields, so if I make all 4 fields as required I will get 4 error messages, not ideal....
    Ideas Please??
    Idea as I was writing this.... Since Button.section.0 is hidden, I can toggle the .required flag on that?  But I still need a script that will set/clear the .required when the user select -any- of the checkboxes/buttons
    In case people are interested, all my sections are different sizes, but Button.section.0 contains the "Section Name" ('Grounds' for example) and when (Button.Section.number).value  = "MAX" you have reached the end of -that- section. It works very nicely and is FAST becasue the build is only done when requested, not continously..
    PS...this works with PC Reader ONLY.  Android reader does not support this but qPDF for Android does.

    I had the same problem; hopefully my solution will be of help to anyone searching this problem via a search engine.
    http://forums.adobe.com/message/4347266#4347266
    Individual radio buttons cannot be named (only the overal exclusion group can be named) or else rawValues will not export.

  • Radio button names disappear in Fields menu

    I'm having this very odd experience in which the names of radio buttons I've created and grouped randomly disappear in the Fields menu.
    That probably doesn't describe it too well, so here's what I'm seeing:
    Notice how there's a gap between "Choice1" and "Choice3"? It should read "Choice2". If you look at the form itself, there are clearly five radio buttons.
    The 'invisible' buttons in the menu disappear randomly once I create more buttons. Sometimes it's "Choice2", sometimes it's "Choice5".
    Any thoughts/suggestions?
    Thanks!

    I had the same problem; hopefully my solution will be of help to anyone searching this problem via a search engine.
    http://forums.adobe.com/message/4347266#4347266
    Individual radio buttons cannot be named (only the overal exclusion group can be named) or else rawValues will not export.

  • How to change button names linked with the 'connect command?'

    Hi,
    I have linked a button in the sequence view to the Exeution entry point 2 (Single Pass) using the 'Connect command'. The button now displays 'Single Pass' as its caption name while running. I want to give a custom name to this button, but it should still be connected to the single pass function. How can rename it?
    Regards
    Gopal

    Hi,
    see this link: http://forums.ni.com/ni/board/message?board.id=330&message.id=7318&query.id=380755#M7318
    You will find the Text for the buttons in one of the ini files. Use the CustomStrings.ini to define your new text, which will override the text defined in the other ini file located in the NI folder when the Operator Interface or SeqEditor first launched and loads the various resources.
    Hope this helps
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • Wrong Button Name in Find/Change-Dialogue

    The button "Find/Change" in the Find/Change-Dialogue has a wrong name. Its behaviour is just the opposite: First it changes, then it searches again. The correct name can only be: "Change/Find".
    (This is part of the Wishlist already and published elsewhere.)

    Ok, I was to quick, sorry. I did not check the english version. I was talkin about the german version. So it is clear: The english version is correct, the german localisation is wrong. This is one of the many, many translation errors of the German Version.
    Is there anybody out there at Adobe who is able to take in such hints regarding the german version? I could collect all and send them in german (!).

Maybe you are looking for

  • IMAP email accounts dont take up space

    Just today I decided to add my email accounts to mac mail app.  I added: a Gmail a Yahoo a companydomain.com//Brinkster account which should be IMAP and i configured it as such a godaddy domain.com account which is not IMAP so i configured it as POP3

  • Avoid timeout error in IC through coding

    Hi Experts, I have a requirement to avoid timeout error in interaction centre ,not through RZ* parameters. but by coding in ICCMP_HEADER, headerviewset.htm. Has anyone faced this before, can you pls share your ideas. Highly rewarded. Regards, Lakshmi

  • Oracle 11g for Ubuntu ?

    Hi, Is Oracle 11g supported on Ubuntu ? which flavor ? If not, which is the standard Linux distribution Oracle considers fit for Oracle 11g ? regards raghav..

  • Problem with offset length

    Hi, i have a problem with offset length please see below code and suggest : data: content_new                LIKE soli-line.   "It has a length of 255 charecter content_new = 'MTE:SD0\nwssd01_SD0_00\CPU\CPU_Utilization'. content_new = content_new+4(2

  • My Form did not run

    hi i tried to buidl a test form with forms builder 11g when i'm trying to start (execute) the form i had blank page in the ie but in the WLS_FORMS i had this ==================== 17/10/2009 03:04:07 ع oracle.dms.wls.DMSServletFilter doFilter WARNING: